Are you trying to insert data into two different tables, and want to use the primary ID generated from the first table in the INSERT into the second table? If so, I'd say use mysql_insertt_id() to grab the ID value and use it in the subsequent insert query/queries.
yes, and so it is mysql_insert_id()
(although I could have provided the key column too).
look into using transactions. See the MySQL manual page: 12.3. MySQL Transactional and Locking Statements.
But I see thats mysql 5.5 and I'm on 4 for other reasons.
So I'll either have to try mysql_insert_id() , or do a layout having "more complete" tables with possibly redundant columns, or stuff everything into a single table.
Maybe I can live without the rollback -- these are for basic survey data.
I did find another way which claims a rollback -- but that too uses php 5 with $querylog
For inserting the PID into second table:
Also came across this example at http://php.net/manual/en/function.mysql-insert-id.php and I can't see why it wouldn't work as long as it is done before the main insert.
<?php
function get_current_insert_id($table)
{
$q = "SELECT LAST_INSERT_ID() FROM $table";
return mysql_num_rows(mysql_query($q)) + 1;
}
?>