title: Using PHP to upload file and add the path to MySQL database
body: <p>Upload.php:</p>
  
  <pre><code>&lt;?php
  
  //This is the directory where images will be saved
  $target = "pics";
  $target = $target . basename( $_FILES['Filename']['name']);
  
  //This gets all the other information from the form
  $Filename=$_POST['Filename'];
  $Description=$_POST['Description'];
  $pic=($_FILES['Filename']['name']);
  
  
  // Connects to your Database
  mysql_connect("localhost", "root", "") or die(mysql_error()) ;
  mysql_select_db("altabotanikk") or die(mysql_error()) ;
  
  //Writes the information to the database
  mysql_query("INSERT INTO picture (Filename,Description)
  VALUES ('$Filename', '$Description')") ;
  
  //Writes the Filename to the server
  if(move_uploaded_file($_FILES['Filename']['tmp_name'], $target)) {
      //Tells you if its all ok
      echo "The file ". basename( $_FILES['uploadedfile']['Filename']). " has been uploaded, and your information has been added to the directory";
  } else {
      //Gives and error if its not
      echo "Sorry, there was a problem uploading your file.";
  }
  ?&gt;
  </code></pre>
  
  <p>And here is the form(in a separate file):</p>
  
  <pre><code>&lt;form method="post" action="upload.php" enctype="multipart/form-data"&gt;
      &lt;p&gt;Photo:&lt;/p&gt;
      &lt;input type="file" name="Filename"&gt; 
      &lt;p&gt;Description&lt;/p&gt;
      &lt;textarea rows="10" cols="35" name="Description"&gt;&lt;/textarea&gt;
      &lt;br/&gt;
      &lt;input TYPE="submit" name="upload" value="Add"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The errors are </p>
  
  <pre><code> Undefined index: Filename on Line 17
  </code></pre>
  
  <p>(the     $Filename=$_POST['Filename'];)</p>
  
  <p>and</p>
  
  <pre><code>Undefined index: uploadedfile on Line 35
  </code></pre>
  
  <p>(the echo "The file ". basename( $_FILES['uploadedfile']['Filename']). " has been uploaded, and your information has been added to the directory";)</p>
  
  <pre><code>echo"&lt;pre&gt;".print_r($_FILES,true)."&lt;/pre&gt;";
  </code></pre>
  
  <p>gives me:</p>
  
  <pre><code>Array
  (
      [Filename] =&gt; Array
          (
              [name] =&gt; Laserkanon.jpg
              [type] =&gt; image/jpeg
              [tmp_name] =&gt; C:\WampServer\tmp\php11D4.tmp
              [error] =&gt; 0
              [size] =&gt; 41813
          )
  
  )
  </code></pre>