title: How to store image link in database php/mysql
body: <p>I'm trying to allow an admin upload pictures of products in to the database, but I only want to store the link/url of the picture in the database and then store the uploaded file in a folder.
  This is what I've got so far, and I keep getting "<em>Sorry there was a problem uploading your file</em>".</p>
  
  <p>Here is the <code>PHP</code> code: </p>
  
  <pre><code>if ($_FILES['product_image']['error'] == 0) { // checking the file for any errors
      $imgName = mysql_real_escape_string($_FILES['product_image']['name']); //returns the name of the image and stores it in variable $imgName
      $imgData = mysql_real_escape_string(file_get_contents($_FILES["product_image"]["tmp_name"])); // returns the content of the file and stores it in $imgData 
      $imgType = mysql_real_escape_string($_FILES["product_image"]["type"]); //returns image/whatever the image type is
  
      $targetFolder = "ProductImages/"; //directory where images will be stored...
      $targetFolder = $targetFolder . basename($imgName); //adds the image name to the directory
  }
  
  $sql = "INSERT INTO products " . "(product_name,product_model,product_price,product_width,product_height,product_weight,product_quantity,product_category,product_subcategory, product_image, product_description,date_added) " . "VALUES('$product_name','$product_model','$product_price','$product_width','$product_height','$product_weight','$product_quantity', '$product_category', '$product_subcategory', '$imgName', '$product_description', NOW())";
  //echo $sql;
  mysql_select_db('online_store');
  $result     = mysql_query($sql, $conn);
  $itemResult = "";
  if (!$result) {
      die('Could not enter data: ' . mysql_error());
  }
  $itemResult = "Product has been added";
  if (move_uploaded_file($imgData, "$targetFolder" . $imgName)) { // writes/stores the image in the targetfolder-&gt;ProductImages
      echo "The file " . basename($imgName) . "has been uploaded!";
  } else {
      echo "Sorry, there was a problem uploading your file!";
  }
  </code></pre>
  
  <p>and the <code>HTML</code> form:</p>
  
  <pre><code>&lt;form id="product_form" name="product_form" enctype="multipart/form-data" action="inventory_list.php" method="post"&gt;
  
  &lt;label for="product_image"&gt;Product Image*:&lt;/label&gt; &lt;input type="file" name="product_image"id="product_image"/&gt;
              &lt;/div&gt;
  &lt;div&gt;
              &lt;button name="add" id="add"&gt;Add Item&lt;/button&gt;
              &lt;/div&gt;
  &lt;/form
  </code></pre>