title: Upload Text and Image with one form, storing path and text in database with PHP
body: <p>I've been working on this code for the last week and its racking my brain. I've searched on forums high and low and can only find very little on this specific subject.</p>
  
  <p>I want to use a form to upload Text and images. Images get uploaded to directory (upload/), while image path and text is INSERTed INTO database table (upgrade.Testimonials). The index, uploader php, and upload folder all exist at www.mywebsite.com/testimonials</p>
  
  <p>UPON EXECUTING THE FORM I RECEIVE A "Connected to $ftp_server, for user $USERNAME SAVED
  Stored in: upload/" BUT NO PHOTO IS UPLOADED AND THE PATH STORED IN DB HAS NO TITLE. BUT ALL OTHER INFORMATION IS SUBMITTED TO DATABASE FINE.</p>
  
  <p>I've opened it the file_upload.php in TextWrangler and it doesn't give me any errors. Hosting with Godaddy.</p>
  
  <p>Other than NY major vulnerability to SQL Injection, 
  why am i not able to upload the images!?</p>
  
  <p>Here is what I have so far, please help!</p>
  
  <blockquote>
    <p>file_upload.php</p>
  </blockquote>
  
  <pre><code>       &lt;?php
  if(isset($_POST['add']))
  {
  $dbhost = '';
  $dbuser = '';
  $dbpass = '';
  $db_name = 'upgrade';
  $tbl_name = 'Testimonials';
  $ftp_user = '';
  $ftp_pass = '';
  $conn = mysql_connect($dbhost, $dbuser, $dbpass);
  if(! $conn )
  {
    die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("$db_name")or die("cannot select DB");
  
  
  $ftp_server = "";
  $ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
  // login with username and password
  $login_result = ftp_login($ftp_conn, $ftp_user, $ftp_pass);
  
  
  // check connection
  if ((!$ftp_conn) || (!$login_result)) {
         echo "FTP connection has failed!";
         echo "Attempted to connect to $ftp_server for user $ftp_user";
         exit;
     } else {
         echo "Connected to $ftp_server, for user $ftp_user";
   }
  
  
  $Fname = $_POST['fname'];
  $Email = $_POST['email'];
  $Content = $_POST['content'];
  $filePath="http://www.mywebsite.com/testimonials/upload/" . $_FILES["file"]["name"];
  $Type = $_POST['type'];
  
   if ($_FILES["file"]["error"] &gt; 0)
    {
       echo "Error: NO CHOSEN FILE &lt;br /&gt;";
       echo"INSERT TO DATABASE FAILED";
     }
     else
     {
       move_uploaded_file($_FILES["file"]["tmp_name"], __DIR__ . "/upload/" . $_FILES["file"]["name"]);
       echo"SAVED&lt;br&gt;";
  
  
  
  $query_image = "INSERT INTO $tbl_name (fname, email, content, image,type, submission_date) VALUES ('$Fname','$Email','$Content','$filePath','$Type',curdate())";
  if(mysql_query($query_image))
  {
  echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
  }
  else
  {
  echo 'File name not stored in database';
  }
  }
  }
  
  
  
  ?&gt;
  </code></pre>
  
  <blockquote>
    <p>The Form from INDEX.php</p>
  </blockquote>
  
  <pre><code>&lt;form method="post"  enctype="multipart/form-data" action="/testimonials/file_upload.php"&gt;
  &lt;table&gt;
  &lt;tr&gt;
  &lt;td width="250"&gt;Name&lt;/td&gt;
  &lt;td&gt;
  &lt;input name="fname" type="text" id="fname" /&gt;&lt;br /&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td width="250"&gt;Email: (will not be publicized)&lt;/td&gt;
  &lt;td&gt;
  &lt;input name="email" type="text" id="email" /&gt;&lt;br /&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td width="250"&gt;Client Type&lt;/td&gt;
  &lt;td id="mainselection"&gt;
  &lt;select name="type" id="type"&gt;
      &lt;option&gt;&lt;/option&gt;
      &lt;option value="Residential"&gt;Residential&lt;/option&gt;
      &lt;option value="Business"&gt;Business&lt;/option&gt;
  
  &lt;/select&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td width="250"&gt;Comments&lt;/td&gt;
  &lt;td&gt;
  &lt;textarea id="content" name="content" rows="10" cols="50" style="border-style:groove;box-shadow: 4px 4px 4px 4px #888888;"placeholder="Please describe your experience"&gt;&lt;/textarea&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td width="250"&gt;Image&lt;/td&gt;
  &lt;td&gt;
  &lt;input name="image" type="file" id="file"&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td width="250"&gt; &lt;/td&gt;
  &lt;td&gt;
  &lt;input name="add" type="submit" id="add" value="Add Testimonial"&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>