IDENTITY_INSERT error?????

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
gasoga
Forum Commoner
Posts: 36
Joined: Thu Apr 17, 2003 4:15 am
Location: Ireland

IDENTITY_INSERT error?????

Post 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!! :)
chris22
Forum Newbie
Posts: 11
Joined: Tue Apr 22, 2003 9:45 pm

Post by chris22 »

Don't insert into the auto incrementing field. Just leave it blank and it will automatically auto increment.
gasoga
Forum Commoner
Posts: 36
Joined: Thu Apr 17, 2003 4:15 am
Location: Ireland

Post by gasoga »

Cheers thanx !! Got it fixed!!!
Post Reply