Mysql
 sql >> Database >  >> RDS >> Mysql

Due inserti in PHP/MySQL usando LAST_INSERT_ID() e righe da un'altra tabella

Potresti usare mysql_insert_id()

$query1 = mysql_query("INSERT INTO events (name , location , date) VALUES ('".mysql_real_escape_string($name)."' , '".mysql_real_escape_string($location)."' , '".mysql_real_escape_string($date)."')");

$insert_id = mysql_insert_id() ;

$query2 = mysql_query("INSERT INTO attendance (event_ID , member_ID) SELECT {$insert_id}, members.member_ID FROM members") ;