title: PHP File/Image not uploading in a folder and saving file name in PHP Database
body: <p>Alright I have way to much time invested in this. I am new to PHP programming and trying to grasp the basics, but I am a little lost as of last night I was able to get a PHP form to upload basic data like a name address and stuff to my (MySQ - PHPL) server.</p>
  <p>But today I said let's do the next step which would be an image to the server. I have watched 3 videos on YouTube probably a 100 times trying it in so many different ways and still haven't been able to get it.</p>
  <p>I'm trying to update the details of my barangay including its logo. Updating other details were successful but uploading the image file, updating the b_logo field as well isn't working.</p>
  <p>Here's my code,</p>
  <pre><code>if(isset($_POST['updateBarangay'])){
  $b_barangay=$_POST['b_barangay'];
  $b_city=$_POST['b_city'];
  $b_province=$_POST['b_province'];
  $b_zip=$_POST['b_zip'];
  $b_id=$_POST['b_id'];
  $file_name = $_FILES['file']['name'];
  $file_type = $_FILES['file']['type'];
  $file_size = $_FILES['file']['size'];
  $file_loc = $_FILES['file']['tmp_name'];
  $file_store = &quot;img/&quot;.$file_name;
  move_uploaded_file($file_loc, $file_store);
  
  $sql = &quot;UPDATE b_details SET b_barangay=?, b_city=?, b_province=?, b_zip=?, b_logo=? WHERE b_id=?&quot;;
  $stmt = $con-&gt;prepare($sql);
  $stmt-&gt;bind_param(&quot;ssssss&quot;, $b_barangay, $b_city, $b_province, $b_zip, $file_name ,$b_id);
  $stmt-&gt;execute();
  
  $action = &quot;Barangay Config | Updated Barangay Details&quot;;
  $date= date(&quot;Y-m-d&quot;);
  $time= date(&quot;h:i:sa&quot;);
  
  $sqlinsert = &quot;INSERT INTO tbl_logs (logs_name, logs_action, logs_position, logs_username, logs_date, logs_time) VALUES (?, ?, ?, ?, ?, ?)&quot;;
  $stmtinsert = $con-&gt;prepare($sqlinsert);
  $stmtinsert-&gt;bind_param(&quot;ssssss&quot;,  $_SESSION['user_fullname'], $action,  $_SESSION['user_position'], $_SESSION['user_username'], $date, $time);
  $stmtinsert-&gt;execute();
  
  if(! $stmt) {
      echo &quot;error&quot;;
  }else{
      header(&quot;location: config&quot;);
  }}
  </code></pre>
  <p>By running this code, I was able to update the other details except b_logo. I'm trying to get the file name then upload it into a folder. Here's what it looks like after running the code,
  <a href="https://i.stack.imgur.com/TAiPF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TAiPF.png" alt="Database Output" /></a></p>
  <p>Here's my HTML Code supporting the PHP code:</p>
  <pre><code>&lt;div class=&quot;col-md-6&quot;&gt;
        &lt;div class=&quot;tile&quot;&gt;
          &lt;h3 class=&quot;tile-title&quot;&gt;Barangay Details&lt;/h3&gt;
          &lt;div class=&quot;tile-body&quot;&gt;
          &lt;?php 
              $sql = &quot;SELECT * FROM b_details&quot;;
              $result = $con-&gt;query($sql) ;
              while($row = $result-&gt;fetch_assoc()) { ?&gt;
            &lt;form class=&quot;form-horizontal&quot; action=&quot;controller&quot; method=&quot;POST&quot; onsubmit=&quot;return confirm('Proceed updating the details of Barangay?')&quot;&gt;
              &lt;div class=&quot;form-group row&quot;&gt;
                &lt;label class=&quot;control-label col-md-3&quot;&gt;Barangay:&lt;/label&gt;
                &lt;div class=&quot;col-md-8&quot;&gt;
                  &lt;input class=&quot;form-control&quot; type=&quot;text&quot; name=&quot;b_barangay&quot; value=&quot;&lt;?php echo $row['b_barangay']; ?&gt;&quot; required&gt;
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;form-group row&quot;&gt;
                &lt;label class=&quot;control-label col-md-3&quot;&gt;City:&lt;/label&gt;
                &lt;div class=&quot;col-md-8&quot;&gt;
                   &lt;input class=&quot;form-control&quot; type=&quot;text&quot; name=&quot;b_city&quot; value=&quot;&lt;?php echo $row['b_city']; ?&gt;&quot; required&gt;  
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;form-group row&quot;&gt;
                &lt;label class=&quot;control-label col-md-3&quot;&gt;Province: &lt;/label&gt;
                &lt;div class=&quot;col-md-8&quot;&gt;
                &lt;input class=&quot;form-control&quot; type=&quot;text&quot; name=&quot;b_province&quot; value=&quot;&lt;?php echo $row['b_province']; ?&gt;&quot; required&gt;
              &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;form-group row&quot;&gt;
                &lt;label class=&quot;control-label col-md-3&quot;&gt;ZIP Code: &lt;/label&gt;
                &lt;div class=&quot;col-md-8&quot;&gt;
                &lt;input class=&quot;form-control&quot; type=&quot;text&quot; name=&quot;b_zip&quot; value=&quot;&lt;?php echo $row['b_zip']; ?&gt;&quot; required&gt;
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;form-group row&quot;&gt;
                &lt;label class=&quot;control-label col-md-3&quot;&gt;Barangay Logo:&lt;/label&gt;
                &lt;div class=&quot;col-md-8&quot;&gt;
                  &lt;input type=&quot;file&quot; name=&quot;file&quot;/&gt;
                  
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;form-group row&quot;&gt;
                &lt;div class=&quot;col-md-8 col-md-offset-3&quot;&gt;
                &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;tile-footer&quot;&gt;
            &lt;div class=&quot;row&quot;&gt;
              &lt;div class=&quot;col-md-8 col-md-offset-3&quot;&gt;
              &lt;input type=&quot;hidden&quot; name=&quot;b_id&quot; value=&quot;&lt;?php echo $row['b_id']; ?&gt;&quot;&gt;
                &lt;button class=&quot;btn btn-success&quot; type=&quot;submit&quot; name=&quot;updateBarangay&quot;&gt;&lt;i class=&quot;fa fa-fw fa-lg fa-check-circle&quot;&gt;&lt;/i&gt;Update&lt;/button&gt;
              &lt;/div&gt;
              &lt;/form&gt;
              &lt;?php } ?&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class=&quot;clearix&quot;&gt;&lt;/div&gt;
  </code></pre>
  <p>Your help would be much appreciated! Thank you so much!</p>