title: How to insert image path in to database?
body: <p>How do is store the image path in database and display it after it is uploaded?</p>
  
  <pre><code>&lt;?php
  $sub=0;
  ini_set( "display_errors", 0);
  if(isset($_REQUEST['submited'])) {
  // your save code goes here
  
  $allowedExts = array("jpg", "jpeg", "gif", "png");
  $extension = end(explode(".", $_FILES["file"]["name"]));
  if ((($_FILES["file"]["type"] == "image/gif")
  || ($_FILES["file"]["type"] == "image/jpeg")
  || ($_FILES["file"]["type"] == "image/png")
  || ($_FILES["file"]["type"] == "image/pjpeg"))
  &amp;&amp; ($_FILES["file"]["size"] &lt; 2097152)
  &amp;&amp; in_array($extension, $allowedExts))
  {
  if ($_FILES["file"]["error"] &gt; 0)
  {
  echo "Return Code: " . $_FILES["file"]["error"] . "&lt;br&gt;";
  }
  else
  {
  echo "";
  if (file_exists("images/" . $_FILES["file"]["name"]))
  {
  echo "&lt;font size='4' color='red'&gt;&lt;b&gt;We are sorry, the file you trying to upload already exists.&lt;/b&gt;&lt;/font&gt;";
    }
  
  else
  {
  move_uploaded_file($_FILES["file"]["tmp_name"],
  "images/" . $_FILES["file"]["name"]);
  $sub= 1;
  echo "&lt;font size='7' color='white'&gt;&lt;b&gt; Success! Your photo has been uploaded.&lt;/b&gt;&lt;/font&gt;";
  
  }
  
  }
  }
  else
  {
  echo "&lt;font size='4' color='red'&gt;&lt;b&gt;We are sorry, the file you trying to upload is not an image or it exceeds 2MB in size.&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;font color='blue'&gt;&lt;i&gt;Only images under size of 2MB are allowed&lt;/i&gt;&lt;/font&gt;.";
  }
  }
  
  ?&gt;
  &lt;form action="" method="post" enctype="multipart/form-data"&gt;
  &lt;input type="hidden" name="submited" value="true" /&gt;
  
  &lt;?php
  ini_set( "display_errors", 0);
  if($sub==0)
  {
  ?&gt; 
  &lt;label size="16" for="file"&gt;Choose Photo:&lt;/label&gt;
  &lt;input id="shiny" type="file" name="file" onchange="file_selected = true;"&gt;
  &lt;input id="shiny" type="submit" value="Upload" name="submit"&gt;
  &lt;?php
  }
  ?&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>here is the database info...and how do I display the picture after inserting the image path in to database? I tried <code>VALUES
      ('$_FILES["file"]["name"]')";</code> but that doesn't seem to work..</p>
  
  <pre><code>&lt;?php
  $con = mysql_connect("localhost","root","");
  if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  
  mysql_select_db("simple_login", $con);
  
  $sql="INSERT INTO photo (photo)
  VALUES
  ('$_FILES["file"]["name"]')";
  
  if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
  
  mysql_close($con);
  ?&gt; 
  </code></pre>