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:
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:
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.
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.