I'm working in Dreamweaver and I need to create an insert form that will add the data from the form into two tables in the database. I've found tons of instructions for creating a form to insert data into one table, but I can not find a tutorial that will take me through the steps of how to insert data into two tables in one transaction with one insert form. Does anyone have a great tutorial out there on this?
Thanks for the heads up. Does anyone have any good tutorials on this? I need a tut that will take me through the steps. Thanks in advance for your help on this.
Well basically you start by inserting data into one table. Then, to get the unique ID of the record you just added (assuming you have an auto-increment primary key field), you do something like
$lastID = mysql_insert_id();
Then you can use that ID as a foreign key when inserting data into the second table
You could always create a "unique identifier" for each entry on your own. I don't know what exactly you are storing into the db, but I'll give a generic example.
//generate unique serial off of the current date, easy enough $unique = date(U); $name = $_POST['name']; $email = $_POST['email']; //and so on,
//run your two queries, you can link them by puting that $unique var into both tables, then when you query for them you can use \"WHERE unique = '$unique'\" or something of the sort.
Then you can use that ID as a foreign key when inserting data into the second table
if that makes any sense at all.