Insert into two tables using Scope_Identity PHP and SQL Server 2008

gaegeagha

New Member
I am building an online shop website that lets a user buy items online. Once the user clicks on "Confirm Order" the following query runs:\[code\]$tsql = "DECLARE @NewID INT INSERT INTO orders (orderDate, customerID, price_total) VALUES (GETDATE(),'$custID','$totalPrice') SELECT @NewID = SCOPE_IDENTITY() INSERT INTO order_items (orderID, price) VALUES ('@NewID', '$totalPrice')"; $stmt = sqlsrv_query($conn,$tsql);\[/code\]orderID column in "orders" table is a primary key and is auto-incremented. I want to be able to get that orderID that was just inserted in "orders" table and insert it in "order_items" table along with other relevant information.The record does get added to the "orders" table, but nothing gets added to the "order_items" table. I am not sure if my query is right. I followed several tutorials that explained scope_identity but as I'm very new to sql and php I might have made a mistake somewhere.
 
Back
Top