title: Upload image to web server and store path in database
body: <p>I am trying to upload image to my webserver using php and to store the path of image in mysql database, I'm not able to do this. Any help would be appreciated. When I hit submit, I could see a blank php page..</p>
  
  <p><strong><em>post.php</em></strong></p>
  
  <pre><code>&lt;?php
  
  
  $dbhost = "localhost";
  $dbuser = "root";
  $dbpass = "";
  
  $name = $_POST['ctitle'];
  $description = $_POST['cdesc'];
  $image = $_FILES['image']['name'];
  $filepath = "images/";
  $filepath = $filepath . basename($image);
  
  if(move_uploaded_file($image, $filepath)){
  $con = mysql_connect($dbhost, $dbuser, $dbpass);
  if(! $con )
  {
    die('Could not connect: ' . mysql_error());
  }
  $sql="INSERT INTO bbmp (dt,title,description,filename,img_path)
  VALUES (NOW(), '$name','$description','$image','$filepath')";
  
  mysql_select_db('bbmp',$con);
  $retval = mysql_query( $sql, $con );
  if(! $retval )
  {
    die('Could not enter data: ' . mysql_error());
  }
  echo "Entered data successfully\n";
  mysql_close($con);
  }
  
  ?&gt; 
  </code></pre>
  
  <p><strong><em>index.html</em></strong></p>
  
  <pre><code>   &lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
          &lt;meta charset="UTF-8"&gt;
          &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
          &lt;h1&gt;Post your complaints here&lt;/h1&gt;
          &lt;form method="POST" action="post.php"&gt;
                  &lt;input type="name" name="ctitle"&gt;&lt;br /&gt;
                  &lt;textarea name="cdesc"&gt;&lt;/textarea&gt;&lt;br /&gt;
                  &lt;input type="file" name="image" &gt;&lt;br /&gt;
                  &lt;input type="submit" name="submit" value="submit"&gt;
          &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong><em>sql</em></strong></p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `bbmp` (
    `id` int(100) unsigned NOT NULL AUTO_INCREMENT,
    `dt` datetime NOT NULL,
    `title` varchar(255) NOT NULL,
    `description` varchar(255) NOT NULL,
    `filename` varchar(255) NOT NULL,
    `img_path` int(255) NOT NULL,
    UNIQUE KEY `id` (`id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
  </code></pre>