title: How to insert into table which contain foreign key
body: <p>i'm newbie, i gotta problems,
  i cannot update table upload since i was insert foreign key from table request in there
  anyone can help me?</p>
  
  <pre><code>table request:
  id_request; Primary Key
  subjek;
  email;
  reportto;
  pelaksana;
  isi;
  
  table upload:
  id_upload; Primary Key
  id_request;  Foreign Key
  filename;
  filetype;
  filesize;
  filedata;
  </code></pre>
  
  <p>if i wanna create new request, it will create record in table request, insert the data to table request, but also insert id_request in table upload, i fill in with last_insert_id</p>
  
  <p>in the same time, after i was insert into id_request in table upload, i was insert attachment using query to by insert or update query
  but there always error</p>
  
  <p>the error was looking like this :</p>
  
  <p>Warning: mysql_query() [function.mysql-query]: MySQL server has gone away in C:\wamp\www\beta\insert.php on line 32</p>
  
  <p>Warning: mysql_query() [function.mysql-query]: Error reading result set's header in C:\wamp\www\beta\insert.php on line 32</p>
  
  <p>this is line 32
  <code>mysql_query($up)or die('Error upload file');</code></p>
  
  <p>this is my listing code</p>
  
  <pre><code>&lt;?php
  include('config.php');
  session_start();
  
  $jenis = $_POST['jenis'];
  $subjek = $_POST['subject'];
  $username = $_SESSION['username'];
  $email = $_SESSION['email'];
  $reportto = $_SESSION['reportto'];
  $pelaksana = $_POST['pelaksana'];
  $ket = $_POST['isi'];
  
  $uploaddir = 'attach/';
  $filedata = addslashes(fread(fopen($_FILES['uploadfile']['tmp_name'], 'r'),
             $_FILES['uploadfile']['size']));
  $filetype = $_FILES['uploadfile']['type'];
  $filesize = $_FILES['uploadfile']['size'];
  $filename = $_FILES['uploadfile']['name'];
  
  $query = "INSERT INTO request (waktu, jenis_request, subject, customer, isi, pelaksana)
      VALUES (NOW(), '".$jenis."', '".$subjek."', '".$username."', '".$ket."', '".$pelaksana."')";
  mysql_query($query)or die('Error, insert query failed');
  $ff = mysql_query("insert into upload (id_request) select id_request from request where id_request = LAST_INSERT_ID()");
  
  $up = "update upload set deskripsi = '".$subjek."' , filetype = '".$filetype."', filename = '".$filename."',  filedata = '".$filedata."', filesize = '".$filesize."' where id_request =     last_insert_id()";
  mysql_query($up)or die('Error upload file');
  
  $uploadfile = $uploaddir . $filename;
  if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $uploadfile)) 
  {
  echo "File telah diupload\n";
  echo '$filename\n';
  //  header("location: home.php");
  
  } 
  else 
  {
  echo "File gagal diupload";
  }
  ?&gt;
  </code></pre>