Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could use: <a href="http://php.net/manual/en/mysqli.insert-id.php" rel="nofollow">http://php.net/manual/en/mysqli.insert-id.php</a></p> <p>mysql_insert_id</p> <p>Finds the last id updated or set and stores it. We then check to make sure the last id does not exist.</p> <p>so...</p> <pre><code>//last id being the id of the last query set or updated $last_id = $mysql-&gt;insert_id; if($last_id != $id) { //execute code { else { echo "last id already in database!"; } </code></pre> <p>If I misinterpreted the question you should still be able to see how to use that last id to do what you want.</p> <p>Here is an example of it being used. First we update the table with the form data which created our ID. Then we add the input check boxes array to the last id updated.</p> <pre><code>//define input variables $lesson_id = $_POST['lesson_id']; $user_id = $_POST['user_id']; $instructor_id = $_POST['instructor_id']; $lesson_comments = $_POST['lesson_comments']; $lesson_date = date("Y-m-d"); $video_ids = isset($_POST['checkbox']) ? $_POST['checkbox'] : array(); # this is called a ternary operator //insert lesson information first $query ="INSERT INTO swing_viewer_lessons (lesson_id, user_id, instructor_id, lesson_comments, lesson_date) VALUES (?, ?, ?, ?, ?)"; if ($stmt = $mysqli-&gt;prepare($query)) { $stmt-&gt;bind_param("iiiss", $lesson_id, $user_id, $instructor_id, $lesson_comments, $lesson_date); $stmt-&gt;execute(); //printf($stmt-&gt;error); echo "successful"; //echo "$last_id"; } //insert lesson information if (is_array($video_ids) &amp;&amp; count($video_ids) &gt; 0) { foreach($video_ids as $list); } // Make it into a comma separated list $rec_ids = implode(',', $video_ids); //get last inserted id from above $last_id= $mysqli-&gt;insert_id; //finally query and update lesson information based on the last id added from above $query ="UPDATE swing_viewer_lessons SET video_ids=? WHERE id=?"; if ($stmt = $mysqli-&gt;prepare($query)) { $stmt-&gt;bind_param("si", $rec_ids, $last_id); $stmt-&gt;execute(); } </code></pre> <p>Hopefully this helps you or anyone else for that matter, as at one point I was pulling hair at this.</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.
    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