title: Trouble storing image path into MySQL
body: <p>I'm having troubles understanding the storing of images <strong><em>file path</em></strong> into MySQL database.
  But it is storing the images details as well as moving the image file into directory. I've tried many approaches but no luck. I'm a PHP novice.</p>
  
  <p><strong><em>Question:</em></strong>
  How do I properly capture and store the path to the image into MySQL?</p>
  
  <p><strong><em>Reference Link:</em></strong>
  <a href="http://www.php-mysql-tutorial.com/wikis/php-tutorial/uploading-files-to-the-server-using-php.aspx" rel="nofollow">http://www.php-mysql-tutorial.com/wikis/php-tutorial/uploading-files-to-the-server-using-php.aspx</a></p>
  
  <p><strong><em>Also:</em></strong> Please suggest any better coding practices overall for consideration. Much appreciated!</p>
  
  <pre><code>//MYSQL TABLE
  CREATE TABLE `userimages` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `name` varchar(30) NOT NULL DEFAULT '',
    `type` varchar(30) NOT NULL DEFAULT '',
    `size` int(11) NOT NULL,
    `ipath` varchar(250) NOT NULL DEFAULT '',
    PRIMARY KEY (`id`)
  ) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
  </code></pre>
  
  <p><strong><em>Here are my error messages.</em></strong></p>
  
  <p>Notice: Undefined variable: path in /useradmin-processor.php on line 45</p>
  
  <p>Notice: Undefined index: ipath in /useradmin-processor.php on line 55</p>
  
  <p>Notice: Undefined variable: path in /useradmin-processor.php on line 59</p>
  
  <pre><code>// IMAGE UPLOAD FILE
  if(isset($_POST['imagesupload'])) {
      /*
      Note: The below code will upload the image to the images folder.
      Then store the image name in your database. When you want to show the
      image, just append the image name(taken from database) to the image path
      and paste it in the &lt;img&gt;
      */
      $imageFileName       =   $_FILES["imageFileName"]["name"];
      $tmpImageFileName    =   $_FILES["imageFileName"]["tmp_name"];
      $imageSize           =   $_FILES["imageFileName"]["size"];
      $imageType           =   $_FILES["imageFileName"]["type"];
  
      move_uploaded_file($tmpImageFileName,"images/".$imageFileName);
  
      /*
      Note: You can make sure that the images are not overritten by checking
      if there is a different image with the same file name, by using the
      below code prevents overwriting of images due to same Image names.
      You have to store the new Image name in the database.
      */
      $newImageFileName    =   $imageFileName;
  
      loop1:
  
      if(!file_exists("images/".$newImageFileName)){
          move_uploaded_file($tmpImageFileName, $path.$newImageFileName);
      } else {
          $newImageFileName .= "_1";
          goto loop1;
      }
  
      /*
      Note: store the image details into the database and make the connection.
      */
      $params = array(
          ':$path'=&gt;$_POST['ipath']
      );
  
      $sql = "INSERT INTO userimages ( name, size, type, ipath ) ".
      "VALUES ( '$imageFileName', '$imageSize', '$imageType', '$path' )";
  
      // the connection to db
      executeSQL($sql, $params);
  }
  </code></pre>