php - take data from one table and put it into another along with new information -


i have 2 tables. first customers second invoice, both have row "customer id". when adding new invoice through web form how make take "customer id" customers , put "customer id" in invoice along new information upon submission of form?

this code index.php

?php include 'dbconfig.php'; //insert or update contact information if(isset($_post['action_type'])) { if ($_post['action_type'] == 'add' or $_post['action_type'] == 'edit') {     //sanitize data , assign variables     $invum = mysqli_real_escape_string($link, strip_tags($_post['invnum']));     $cost = mysqli_real_escape_string($link, strip_tags($_post['cost']));      if ($_post['action_type'] == 'add')     {         $sql = "insert invoice set                  cost = '$cost'";     }else{         $sql = "update invoice set                  cost = '$cost',                 invnum = $invnum";     }       if (!mysqli_query($link, $sql))     {         echo 'error saving data. ' . mysqli_error($link);         exit();      } } header('location: invoicelist.php'); exit(); } //end insert or update contact information  //start of edit contact read $gresult = ''; //declare global variable if(isset($_post["action"]) , $_post["action"]=="edit"){ $id = (isset($_post["ci"])? $_post["ci"] : ''); $sql = "select invnum, cost invoice          invnum = $id";  $result = mysqli_query($link, $sql);  if(!$result) {     echo mysqli_error($link);     exit(); }  $gresult = mysqli_fetch_array($result);  include 'invoiceupdate.php'; exit(); } //end of edit contact read 


Comments