title: Trouble storing uploaded file into MySql
body: <p>Hi I'm currently developing a quick prototype for my degree project. I have a previous form where users will select some options from dynamic dropdowns and when these have been saved into the tables the next page is for a user to upload a file. This file is then stored into a separate table with a foreign key referencing one other table. The problem is with the file upload page, I haven't included the the variable that represents the foreign key as i wanted to see if i could get it to work first. If anyone could help it would be much appreciated.</p>
  
  <p>The error i receive is either for the the name of the upload file not being a valid column name in the fields of the insert query or</p>
  
  <p>If I try to change the sql i get insert or update can not be done on a child table as the referential integrity is breached.  </p>
  
  <p>Am I being thick? Ive been stuck for a few hours now.</p>
  
  <p>heres the php</p>
  
  <pre><code>if (isset($_POST['action']) and $_POST['action'] == 'upload')
  {
  
  $uploadfile = $_FILES['upload']['tmp_name'];
  $uploadname = $_FILES['upload']['name'];
  
  if(is_uploaded_file($uploadname)) {
  
  
  $uploadtype = $_FILES['upload']['type'];
  $uploaddata = file_get_contents($uploadfile);
  
  
  
  // Prepare user-submitted values for safe database insert
  
  $uploadname = mysql_real_escape_string($uploadname);
  $uploadtype = mysql_real_escape_string($uploadtype);
  $uploaddata = mysql_real_escape_string($uploaddata);
  
  $sql = "INSERT INTO product_logs (fileName, mimeType, fileData)
          VALUES (".$uploadname.",".$uploadtype.",".$uploaddata.")";
  $exesql=mysql_query($sql) OR die(mysql_error());
  }
  else {
  echo 'Error: File could not be uploaded.';
  }   
  }
  include("file.html.php");  
  </code></pre>
  
  <p>and here is the file.html.php</p>
  
  <pre><code>&lt;form action="" method="post" enctype="multipart/form-data"&gt;
          &lt;div&gt;
              &lt;label for="upload"&gt;Upload File:
              &lt;input type="file" id="upload" name="upload"/&gt;&lt;/label&gt;
          &lt;/div&gt;
          &lt;div&gt;
              &lt;input type="hidden" name="action" value="upload"/&gt;
              &lt;input type="submit" value="Upload"/&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>Here is the structure of the product_logs table</p>
  
  <pre><code>Field       Type           Null Key       Default         Extra
  logID       int(5)         NO   PRI         NULL           auto_increment
  dateCreated date           NO               NULL    
  malResultID int(6)         NO   MUL         NULL    
  mimeType    varchar(50)    NO               NULL    
  fileData    mediumblob     NO               NULL    
  fileName    varchar(255)   NO               NULL
  </code></pre>