Page 1 of 1

IDENTITY_INSERT error?????

Posted: Wed Apr 30, 2003 3:53 am
by gasoga
HI im using ms sql server database, and on my website i have a form that when submitted has an id. I want this id to increment automatically.

The following piece of code submits the info into the database but its not incrementinthe id:

Code: Select all

<?php

$Q03 = "SET IDENTITY_INSERT cust_call_log ON INSERT INTO $dbcall2(id_num,company_name,Username,date,time,call_type,description) VALUES('','$company_name','$Username','$date','$time','$call_type','$description')SET IDENTITY_INSERT cust_call_log OFF	";
$R03 =  odbc_exec($db,$Q03) or die("Bad Q03:".mysql_error()); 

$Q03 = "SET IDENTITY_INSERT logged_cust_calls ON INSERT INTO $dbcust_log(id_num,company_name,date)VALUES('','$company_name','$date')SET IDENTITY_INSERT OFF logged_cust_calls";
$R03 =  odbc_exec($db,$Q03) or die("Bad Q03:".mysql_error()); 


?>
If i dont use the set identity_insert i get an error. Any ideas on how i could fix this or is there other ways of automatically incremting the id ???
Thanx for any advice!! :)

Posted: Wed Apr 30, 2003 3:16 pm
by chris22
Don't insert into the auto incrementing field. Just leave it blank and it will automatically auto increment.

Posted: Thu May 01, 2003 11:14 am
by gasoga
Cheers thanx !! Got it fixed!!!