title: PHP image upload and insert your path into database
body: <p>I have a bug with file's input. True, the image is moved into the server's folder - isset($_FILES['avatar']), is OK - but user_avatar's field isn't filled with your name. It's named with "default_130x130.png" on database. How should I do for send the "$user_avatar" variable, from upload_image.php, towards new_user.php?</p>
  
  <hr>
  
  <p>en/users/new.html</p>
  
  <pre><code>    &lt;form id="avatar_file_upload_form" action="../../utils/upload_image.php" method="post" enctype='multipart/form-data'style="position:absolute;z-index:-10;height:1px;width:1px;overflow:hidden;visibility:hidden;"&gt;
          &lt;input type="file" name="avatar" id="avatar_file_upload_field" accept="image/jpeg,image/pjpeg,image/bmp,image/gif,image/jpeg,image/png"/&gt;
          &lt;input type="submit" /&gt;
      &lt;/form&gt;
  </code></pre>
  
  <hr>
  
  <p>utils/upload_image.php</p>
  
  <pre><code>&lt;?php
  ob_start();
  $mimeExt = array();
  $mimeExt['image/jpeg'] ='.jpg';
  $mimeExt['image/pjpeg'] ='.jpg';
  $mimeExt['image/bmp'] ='.bmp';
  $mimeExt['image/gif'] ='.gif';
  $mimeExt['image/x-icon'] ='.ico';
  $mimeExt['image/png'] ='.png'; 
  if(isset($_FILES["avatar"])) { 
       //Begins image upload
          $user_avatar = md5(uniqid(time())).$mimeExt[$_FILES["avatar"]["type"]]; //Get image extension
          $user_avatar_dir = "../img/".$user_avatar; //Path file
          move_uploaded_file($_FILES["avatar"]["tmp_name"], $user_avatar_dir); 
  
  } else {
      $user_avatar = "default_130x130.png";
  }
  ?&gt;
  </code></pre>
  
  <hr>
  
  <p>new_user.php</p>
  
  <pre><code>&lt;?php
  ob_start();
  include "config.php";
  include "utils/upload_image.php";
  $sql = mysql_query("insert into user(user_avatar) values('$user_avatar')", $db_connection) or die("Error: ".mysql_Error());
  ob_end_clean();
  mysql_close($db_connection);
  ?&gt;
  </code></pre>
  
  <hr>
  
  <p>Note: the "config.php" file works perfectly.</p>