Mysql
 sql >> Base de données >  >> RDS >> Mysql

Deux insertions en PHP/MySQL en utilisant LAST_INSERT_ID() et des lignes d'une autre table

Vous pouvez utiliser 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") ;