title: PHP/MYSQL: Multiple values using same identifying number
body: <p>I am trying to write data from an invoice into 2 tables
  table 1 is the invoices table
  it contains:</p>
  
  <p><code>invoice_id account sales purchase_date</code></p>
  
  <p>then a second table invoice_items it contains the information about each line in the invoice.</p>
  
  <pre><code>id  invoice_id  item    description     quantity    price   amount
  </code></pre>
  
  <p>Basically now I am checking to see if the id exists and if it does I check if the line id exists and if it doesn't it adds the information for the invoice if the id exists it checks to see if the line id exists</p>
  
  <pre><code>$checkin = mysql_query("
  SELECT `id`
  FROM `invoices`
  WHERE `invoices`.`id` =$invoice_id
  ");
  
  if (mysql_num_rows($checkin) == 1) 
  {
    $updatememocount ++;
  
    mysql_query("UPDATE `invoices`  SET `invoices`.`INV_ID` = '".$invid."'WHERE `invoices`.`id` =$invoice_id ") or die("load1 -" . mysql_error());
  
    // check line id
    $checklineid = mysql_query("SELECT `Line_ID` from `invoice_items` WHERE `Line_ID` = '$lineid'") or die("load1 -" . mysql_error());
    if (mysql_num_rows($checklineid) == 0) 
    {
      $insertlinecount ++;
      mysql_query("INSERT INTO `invoice_items` (invoice_id, item, description, quantity, price, amount, Line_ID) VALUES ('".$invoice_id."', '".mysql_real_escape_string($row['3'])."', '".mysql_real_escape_string($row['4'])."', '".$row['9']."', '".$row['7']."', '".$row['5']."', '".$row['14']."' ) ") or die("load1 -" . mysql_error());
    } 
  }
  else
  {
    // makes new invoice entry and enters the line item information for the first line.
  }
  </code></pre>
  
  <p>Data sample this is how the data comes in</p>
  
  <pre><code>Date    Invoice_Id    Item           Description             Price    Amount   Customer_ID   Line_ID
  05/12/12  1234        something     whatever somthing  is     15        15       2255          123
  05/12/12  1234        Another_thing  Whatever that is         25        25       2255          124
  </code></pre>