title: Two inserts in PHP/MySQL using LAST_INSERT_ID() and rows from another table
body: <p>I am working on an events calendar using PHP and MySQL (V5.1) where the admin would add an event, and then an attendance list for that event would be created as well. I have three tables: events, attendance and members. So far I can create the event using information that is entered thorugh a PHP form. I'm trying to update the attendance table by inserting the event id from the event that has just been created, as well as pulling in the list of members (using their member ID) from the members table. Nothing is being added to attendance the table though. Can someone let me know what I should I be doing differently?</p>
  
  <p>Some of the fields I am using in the tables:<br />
  Events: event_ID (Primary key, auto-increment), name, location, date<br /> 
  Attendance: attendance_ID (Primary key, auto-increment),  event_ID, member_ID, attending<br />
  Members: member_ID (Primary key, auto-increment), name, email</p>
  
  <pre><code>enter code here
  </code></pre>
  
  <p>Here is the code:</p>
  
  <pre><code>mysql_query("SET AUTOCOMMIT=0");
  mysql_query("START TRANSACTION");
  
  $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)."')");
  
  $query2 = mysql_query("INSERT INTO attendance (event_ID , member_ID) SELECT LAST_INSERT_ID(), members.member_ID FROM members");
  
  if ($query1 and $query2) { 
  mysql_query("COMMIT");
  } else {
  mysql_query("ROLLBACK");
  </code></pre>
  
  <p>}</p>