Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using mssql and php....scope_identity()

Status
Not open for further replies.

work4free

Technical User
Jul 22, 2004
21
US
I have an online form people fill out and their info is put into our database. I have two tables - tblPerson and tblInfo. The primary key from tblPerson is a foreign key in tblInfo. The way it is setup now is:
Code:
Query1 = Insert into tblPerson (fname, lname, phone) values ('fname', 'lname', 'phone')

Query2 = Select ID from tblPerson WHERE fname = 'fname' AND lname = 'lname' AND phone = 'phone'

Query3 = Insert into tblInfo (building, room, incident, ID) values ('building', 'room', 'incident', 'Query2')

i was told to use scope_identity() in order to a in Query2 in order to get the last ID added. i've never used scope_identity() and i am not sure how to get it to work with PHP. i have tried the following:
Code:
Query2 = mssql_execute(scope_identity());

however, i don't think this is working. what is the best way to insert into one table, get the ID value from that table, and insert into a second table information - including the ID from the first table?


note: I'm using SQL Server 2000.
on the webpage i am using PHP to store and retrieve variables, thus the Query1, 2 & 3. I'm just trying to figure out the SQL to use to plug into PHP.
 
The way you're using scope_identity() is as a PHP function.

If you mean to pass scope_identity() to MSSQL for it to interpret and run, you should wrap the function in quotes:

Query2 = mssql_execute('scope_identity()');


If you need more information on what the function does, that's a question for a MSSQL forum.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
i know what the function does....i'm trying to implement it into PHP. i didn't have the quotes around it....i'll give that a try.

thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top