php - Sending information from a newly created record to a different MySQL table -


i'm making form submits story mysql table called 'work'. want later take id of newly created record , put information different table.

but when submit story, says:

$workid undefined.

i can't see problem though because believe i've defined it?

<?php     if (!empty($_post) && !empty($_post['title']) && !empty($_post['story']) && !empty($_post['genre']) && !empty($_post['rating'])) {          $title = strip_tags($_post['title']);         $story = strip_tags($_post['story']);         $title = mysqli_real_escape_string($db, $title);         $story = mysqli_real_escape_string($db, $story);         $genre = $_post['genre'];         $rating = $_post['rating'];          $query = "select count(*) count works title = '".$title."'";         $result = $db->query($query);         $data = $result->fetch_assoc();          if ($data['count'] > 0) {             echo "<p>story exists!</p>";         } else {             $query = "insert works (author_id, login_id, title, story, genre, rating) values ('".$userid."','".$authorid."','".$title."','".$story."','".$genre."','".$rating."')";              $query = "select `id` `works` `title` = '".$title."'";             if ($result = $db->query($query)) {                 while ($row = $result->fetch_assoc())                      $workid = $row["id"]; //workid written here still considered undefined             }              $query = "insert `author_work` (`author_id`) values ('".$authorid."')";             $result = $db->query($query);              $query = "insert `author_work` (`work_id`) values ('".$workid."')";             $result = $db->query($query);              $query = "insert `login_work` (`work_id`) values ('".$workid."')";             $result = $db->query($query);              $query = "insert `login_work` (`login_id`) values ('".$userid."')";             $result = $db->query($query);                                         if ($result) {                 echo "<p>story submitted!</p>";             } else {                 echo "sql error: " . $db->error;             }         }     } ?> 

you never did $db->query() on insert into... query string, never inserted, , overwritten select id ... query.

$query = "insert works (author_id, login_id, title, story, genre, rating) values ('".$userid."','".$authorid."','".$title."','".$story."','".$genre."','".$rating."')";  $db->query($query); // missing $db->query()  $query="select `id` `works` `title` = '".$title."'"; if ($result = $db->query($query)) { while ($row= $result->fetch_assoc())  $workid = $row["id"];}  

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -