title: PHP upload image to folder and insert record to database
body: <p>I made code in PHP for uploading images, but I have one problem, when I upload image, there is no record in database, but image is uploaded to path where I want it.</p>
  
  <p>this is my code:</p>
  
  <pre><code>&lt;form action="upload.php" method="post" enctype="multipart/form-data" id="upload_form"&gt;
      &lt;input id="file" type="file" name="file[]" /&gt;
      &lt;input type="submit" id="upload" name="submit" value="Dodaj" /&gt;
  &lt;/form&gt;
  
  include 'init.php';
  
      $uploaded = [];
      $allowed = ['jpg', 'png'];
  
      $succeeded = [];
      $failed = [];
  
      if(!empty($_FILES['file'])){
          foreach($_FILES['file']['name'] as $key =&gt; $name){
              if($_FILES['file']['error'][$key] == 0){
                  $temp = $_FILES['file']['tmp_name'][$key];
  
                  $ext = explode('.', $name);
                  $ext = strtolower(end($ext));
  
                  $file = md5_file($temp) . time() . '.' . $ext;              
  
                  if(in_array($ext, $allowed) === true &amp;&amp; move_uploaded_file($temp, "uploads/{$file}") === true){
                      $succeeded[] = array('name' =&gt; $name, 'file' =&gt; $file);
                      $path = 'uploads';
                      $sql = "INSERT INTO users (img_path, img_name, img_type) VALUES ('$path', '$file', '$ext') WHERE id = '$session_user_id'";
                      $result = mysql_query($sql);                    
                  }else{
                      $failed[] = array('name' =&gt; $name); 
                  }               
              }       
          } 
  </code></pre>
  
  <p>init file:</p>
  
  <pre><code>session_start();
  
      mysql_connect('localhost','root','');
      mysql_select_db('croglas'); 
      mysql_query('SET CHARACTER SET utf8');
  
      include 'functions.php';
  
      if(logged_in() === true){
          $session_user_id = $_SESSION['id'];
          $user_data = user_data($session_user_id, 'id', 'username', 'password', 'email', 'address', 'zip', 'phone_number', 'city', 'type', 'points', 'img_path', 'img_name', 'img_type');
      }
  </code></pre>