hi, Am having a problem Inserting into SQL 2008 database using stored procedure from a php webpage.
My Stored Procedure is:
Create PROCEDURE [dbo].[udp_AddContact_Insert]
@Contact_ID int,
@Client_ID int,
@STD varchar(10),
@Tel varchar(20),
@Mobile varchar(20),
@EmailAddress varchar(100),
@FirstName varchar(20),
@LastName varchar(20),
@Title_ID int,
@Position_ID int,
@User_ID int,
@SourceURL varchar(1000),
@PositionText varchar(200),
@TitleText varchar(50),
@NewContact_ID int output
AS
BEGIN
SET NOCOUNT ON
IF LEN(@PositionText)>0 BEGIN
INSERT INTO dbo.tblPosition (Position) VALUES (@PositionText)
SET @Position_ID = @@identity
END
IF LEN(@TitleText)>0 BEGIN
INSERT INTO dbo.tblTitle ([Client_ID], [Title]) VALUES (@Client_ID, @TitleText)
SET @Title_ID = @@identity
END
INSERT INTO [dbo].[tblContact]
([Client_ID]
,[STD]
,[Tel]
,[Mobile]
,[EmailAddress]
,[FirstName]
,[LastName]
,[Title_ID]
,[Position_ID]
,[User_ID]
,[SourceURL])
VALUES
(@Client_ID
,@STD
,@Tel
,@Mobile
,@EmailAddress
,@FirstName
,@LastName
,@Title_ID
,@Position_ID
,@User_ID
,@SourceURL
)
SELECT @NewContact_ID = @@identity
DECLARE @Relationship_ID int
SET @Relationship_ID = 1 --Contact
INSERT INTO [dbo].[tblContact_Related]
([Contact_ID],
[RelatedContact_ID],
[Relationship_ID])
VALUES
(@Contact_ID,
@NewContact_ID,
@Relationship_ID)
SELECT Contact_ID FROM dbo.tblContact WHERE [Contact_ID] = @Contact_ID
END
GO
And my php code is
$Contact_ID = $_POST['contactID'];
$Client_ID = 1;
$STD = "0";
$Tel = "0";
$Mobile = $_POST['mobile'];
$EmailAddress = $_POST['email'];
$FirstName = $_POST['firstname'];
$LastName = $_POST['lastname'];
if($_Post['titleID']=="")
{$Title_ID = 0;}
else $Title_ID = $_Post['titleID'];
if($_Post['position']=="")
{$Position_ID = 0;}
else $Position_ID = $_Post['positionID'];
$User_ID = 0;
$DateCreated = getdate();
$PositionText = $_POST['position'];
$TitleText = $_POST['title'];
$SourceURL = $_POST['sourceurl'];
$proc2 = mssql_init("dbo.udp_AddContact_Insert", $con);
mssql_bind($proc2, "@Contact_ID", $Contact_ID, SQLINT4);
mssql_bind($proc2, "@Client_ID", $Client_ID, SQLINT4);
mssql_bind($proc2, "@STD", $STD, SQLVARCHAR);
mssql_bind($proc2, "@Tel", $Tel, SQLVARCHAR);
mssql_bind($proc2, "@Mobile", $Mobile, SQLVARCHAR);
mssql_bind($proc2, "@EmailAddress", $EmailAddress, SQLVARCHAR);
mssql_bind($proc2, "@FirstName", $FirstName, SQLVARCHAR);
mssql_bind($proc2, "@LastName", $LastName, SQLVARCHAR);
mssql_bind($proc2, "@Title_ID", $Title_ID, SQLINT4);
mssql_bind($proc2, "@Position_ID", $Position_ID, SQLINT4);
mssql_bind($proc2, "@User_ID", $User_ID, SQLINT4);
mssql_bind($proc2, "@SourceURL", $SourceURL, SQLVARCHAR);
mssql_bind($proc2, "@PositionText", $PositionText, SQLVARCHAR);
mssql_bind($proc2, "@TitleText", $TitleText, SQLVARCHAR);
$result2 = mssql_execute($proc2);
Can anyone help me find my mistakes please.
Thanks