Note that there are some explanatory texts on larger screens.

plurals
  1. POInserting into two SQL tables using a value from one
    primarykey
    data
    text
    <p>I am building a simple event registration system using MySQL and PHP. I have four tables:</p> <pre><code>events: event_id, event_name instance: instance_id, event_id, date attendee: attendee_id, attendee_name, attendee_email, attendee_tel registration: reg_id, attendee_id, instance_id </code></pre> <p>To clarify, the instance table contains instances of a given event, ie a specific event on a specific date.</p> <p>When an attendee registers (via a form), I want to write their details to the <code>attendee</code> table, then write the event they have registered for in the <code>registration</code> table, along with the relevant <code>attendee_id</code>, so that when I query the <code>registration</code> table later on, it will show me what event has been registered for and by whom.</p> <p>However, I'm new to SQL (and databases in general, not to mention PHP as well), so I'm not sure how I can do that given that the <code>attendee_id</code> has only just been generated by adding the attendee to the table. I can easily insert a row into the <code>attendee</code> table with:</p> <pre><code>$q = "INSERT INTO attendee (attendee_name, attendee_email, attendee_tel) VALUES ( '$fullname', '$email', '$tel' )"; </code></pre> <p>With the values obviously being grabbed by <code>$_POST</code> from the form. The form also grabs the <code>instance_id</code>, incidentally.</p> <p>So I just need to know how I can insert the relevant information into the <code>registration</code> table. Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload