title: Uploading blob files/images into Mysql
body: <p>I had this php code that take values from an html form (name, file, photo, address,.....), and try to insert or update them in sql database.</p>
  
  <pre><code>&lt;?php 
  $host="localhost"; // Host name 
  $username=""; // Mysql username 
  $password=""; // Mysql password 
  $db_name=""; // Database name 
  $tbl_name=""; // Table name 
  session_start();
  $con=mysqli_connect("localhost","","","");
  
  $id=$_REQUEST['id']; 
  
  //Variable intilisation 
  $name = '';
  $remarcs = '';
  $address = '';
  $test_res = '';
  $date = '';
  $phone = '';
  $new_path = '';
  
  
  
  if (isset ($_POST['name'])) {
      $name = $_POST['name'];
  }
  if (isset ($_POST['remarcs'])) {
      $remarcs = $_POST['remarcs'];
  }
  if (isset ($_POST['test_res'])) {
      $test_res = $_POST['test_res'];
  }
  if (isset ($_POST['address'])) {
      $address = $_POST['address'];
  } 
  
  if (isset ($_POST['date'])) {
      $date = $_POST['date'];
  } 
  
  if (isset ($_POST['phone_num'])) {
      $phone = $_POST['phone_num'];
  }
  
  if(!empty($_FILES)){ //Check file is uploaded or not 
      $check = getimagesize($_FILES["file"]["tmp_name"]);
      if($check !== false) {
          $path = "../uploads/".$_FILES['file']['tmp_name'];
          move_uploaded_file($file, $path);
          $new_path = $path;
          echo "Uploaded";
      } 
      if($check ==  false){
          echo "Not uploaded";
      }
  }
  if(move_uploaded_file($_FILES['file']['tmp_name'], $path)){
  $sql="  update patients set values
              name = '$name',
              echo_photo = 'NULL',
              echo_file = '$new_path',
              remarcs = '$remarcs',
              test_res = '$test_res',
              date = '$date',
              address = '$address',
              phone_num = '$phone' 
          WHERE id = ".$id;
  
  $result=mysqli_query($con,$sql) or die('Unable to execute query. '. mysqli_error($con));
  header("location:update_done.php");
  
  }else{
          header("location:update_false.php");
  
  }
  if($result){
      echo $name."&lt;p&gt;\n&lt;/p&gt;";
      echo $remarcs."&lt;p&gt;\n&lt;/p&gt;";
      echo $test_res."&lt;p&gt;\n&lt;/p&gt;";
      echo $address."&lt;p&gt;\n&lt;/p&gt;";
      echo $phone."&lt;p&gt;\n&lt;/p&gt;";  
  }
  
  mysqli_close($con);
  </code></pre>
  
  <p>?> </p>
  
  <p>The problem is that I am getting the following errors when only I upload a file shown in the image below:
  <a href="https://i.stack.imgur.com/YTEeB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YTEeB.jpg" alt="enter image description here"></a></p>
  
  <p>And when I dont upload a file, I got an error: Please select a file.
  Any help ? Thank you.</p>
  
  <p>This is the html form:</p>
  
  <pre><code>&lt;form action="update.php" id="Form2" method="POST" enctype="multipart/form-data" class="c"&gt;
  &lt;div align="center"&gt;
  &lt;?php echo "Updating information about Patient ".$row["name"]; ?&gt;
  &lt;table class="imagetable" border="1" cellspacing="3"  align="center"&gt;
    &lt;th&gt;Personal Informations&lt;/th&gt;
  &lt;th&gt;Test Results&lt;/th&gt;
  
  &lt;tr&gt;&lt;td&gt;Name&lt;br&gt;
    &lt;input type="text" class="large-fld" name="name" placeholder="Patient Name" value="&lt;?php echo $row['name'];?&gt;"/&gt;&lt;/td&gt;
  &lt;td&gt;Remarcs:&lt;br&gt;
    &lt;textarea type="text" cols="40" rows="5" class="large-fld"  name="remarcs" placeholder="Remarcs"&gt;&lt;?php echo $row['remarcs'];?&gt;&lt;/textarea&gt;&lt;/td&gt;
    &lt;tr&gt;&lt;td&gt;Address&lt;br&gt;
    &lt;input type="text" class="large-fld" name="address" placeholder="Address" value="&lt;?php echo $row['address'];?&gt;"/&gt;
    &lt;/td&gt;
  &lt;td&gt;Test&lt;br&gt;  &lt;textarea type="text" cols="40" rows="5" class="large-fld"  name="test_res" placeholder="Test Result"&gt;&lt;?php echo $row['test_res'];?&gt;&lt;/textarea&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;Phone Number&lt;br&gt;
    &lt;input type="text" class="large-fld" name="phone_num" placeholder="Phone Number" value="&lt;?php echo $row['phone_num'];?&gt;"/&gt;
    &lt;/td&gt;
  &lt;th&gt;Files&lt;/th&gt;
  &lt;/tr&gt;
    &lt;td&gt;Scanned Echo Photo&lt;br&gt;
    &lt;input type="file" class="" name="echo_photo" id="echo_photo" placeholder="Add echo photo" value="&lt;?php echo $row['echo_photo'];?&gt;"/&gt;&lt;/td&gt;
  &lt;td&gt;Echo Files:&lt;br&gt;
        &lt;input type="file" name="file" id="file"  value="&lt;?php echo $row['echo_files'];?&gt;"/&gt;&lt;br&gt;&lt;/td&gt;
    &lt;/tr&gt;&lt;/th&gt;&lt;/table&gt;
    &lt;div class="row" align="center"&gt;
  &lt;input type="submit" name="submit" id="btnUploadId" class="large-btn" value="Update" onClick="btnOnClickUpload()"&gt;
        &lt;input type="hidden" id="courseIdHidden" value="&lt;?php echo $idd; ?&gt;" /&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;/table&gt;&lt;/div&gt;
  &lt;/form&gt;
  </code></pre>