title: only jpg jpeg and .... photos should be uploaded
body: <p>I've been trying to solve this problem for several hours, but it didn't work.</p>
  <p>The problem is:</p>
  <p>I only want to upload photos such as jpg png, but when I upload photos with this type, I get the error message that should only be displayed if the type of uploaded data is wrong.</p>
  <p>I wrote all the code, and I also wrote some parts of the code where the problem might be, sSo that everything is clear for you.</p>
  <pre><code>&lt;?php
  
  //msg for the first name,
  $msg='';
  //msg2 for the last name
  $msg2='';
  
  //msg3 for the email
  $msg3='';
  //msg4 for the date
  $msg4='';
  //msg5 for the password
  $msg5='';
  //msg6 for the re Password 
  $msg6='';
  //msg7 for the image
  $msg7='';
  //msg8 for the checkbox
  $msg8='';
  $msg9='';
  $msg10='';
  
  $firstname='';$lastname='';$email='';$date='';$password='';$c_password='';$image='';
  
  include(&quot;includes\header.php&quot;);
  include(&quot;includes\config.php&quot;);
  
  /**isset: checks if a variable is set, which means that it has to be declared and is not NULL */
  if(isset($_POST['submit']))
  {
  
  //mysqli not mysql`enter code here 
  $firstname=mysqli_real_escape_string($con, $_POST['fname']);
  $lastname=mysqli_real_escape_string($con, $_POST['lname']);
  $email=mysqli_real_escape_string($con, $_POST['mail']);
  $date=$_POST['dob'];
  $password=$_POST['pass'];
  $c_password=$_POST['cpass'];
  $image=$_FILES['image']['tmp_name'];
  $checkbox=isset($_POST['check']);
  
  // this two line was for testin, if all this is ok 
  //echo $firstname. &quot;&lt;br&gt;&quot;.$lastname.&quot;&lt;br&gt;&quot;.&quot;&lt;br&gt;&quot;.$email.&quot;&lt;br&gt;&quot;. &quot;&lt;br&gt;&quot;.$date.&quot;&lt;br&gt;&quot;. &quot;&lt;br&gt;&quot;.$password.&quot;&lt;br&gt;&quot;
  //.&quot;&lt;br&gt;&quot;.$c_password.&quot;&lt;br&gt;&quot;.&quot;&lt;br&gt;&quot;.$image.&quot;&lt;br&gt;&quot;.&quot;&lt;br&gt;&quot;.$checkbox.&quot;&lt;br&gt;&quot;;
  
  //strlen is to returns the length of the string(firstname)
  if(strlen($firstname) &lt;3)
  {
      // This message must be displayed if the number of letters of the given name is less than 3
      $msg=&quot;&lt;div class='error'&gt;First name must contain atleast 3 characters&lt;/div&gt;&quot;;
  }
  
  else if(strlen($lastname) &lt;3)
  {
          // This message must be displayed if the number of letters of the given lastname is less than 3
      $msg2=&quot;&lt;div class='error'&gt;Last name must contain atleast 3 characters&lt;/div&gt;&quot;;
  }
  
  //filter_var: filters the email with  FVE.
  else if(!filter_var($email,FILTER_VALIDATE_EMAIL))
  {
          // This message must be displayed if the number of letters of the given lastname is less than 3
      $msg3=&quot;&lt;div class='error'&gt;Enter Vaild Email&lt;/div&gt;&quot;;
  }
  
  else if (empty($date))
  {
  $msg4=&quot;&lt;div class='error'&gt; Please Enter Your Date of Birth&lt;/div&gt;&quot;;
  }
  
  else if (empty($password))
  {
      $msg5=&quot;&lt;div class='error'&gt; Please Enter Your Password &lt;/div&gt;&quot;;
  
  }
  else if (strlen($password) &lt;5)
  {
  
   $msg5=&quot;&lt;div class='error'&gt;Password must contain atleast 5 Character&lt;/div&gt;&quot; ;   
  
  }
  
  else if ($password!==$c_password)
  {
  
      $msg6=&quot;&lt;div class='error'&gt; Password is not same &lt;/div&gt;&quot;;
  }
  
  else if ($image=='')
  {
  
      $msg7=&quot;&lt;div class='error'&gt; Please Upload Your Profile Image &lt;/div&gt;&quot;;
  }
  
  else if($checkbox=='')
  {
  $msg8=&quot;&lt;div class='error'&gt; Please Agree Our Termas an Conditions &lt;/div&gt;&quot;;
  }
   
  else
  {
  
      $img_ext=explode(&quot;.&quot;,$image);
      $image_ext=$img_ext['1'];
      if($image_ext=='jpg' || $image_ext=='png' || $image_ext=='PNG' || $image_ext=='JPG' || $image_ext=='jpeg' || $image_ext=='JPEG' )
      {
          
          // to conection to the  database and gives the values    
          mysqli_query($con, &quot;INSERT INTO users(first_name,last_name,mail,password,dob,img)
          VALUES ('$firstname', '$lastname','$email','$date','$password','$image')&quot;);
  
          $msg9=&quot;&lt;div class='success'&gt; You are Successfully Registered &lt;/div&gt;&quot;;
          $firstname='';$lastname='';$email='';$date='';$password='';$c_password='';$image='';
      }
  
          else
             {
             $msg7=&quot;&lt;div class='error'&gt; Please Upload an Image File&lt;/div&gt;&quot;;
             }
  
       }
  
  // this slash  is from the if sumbmit
  }
  
  ?&gt;
  
  //this part of code is  from body
  
  &lt;/head&gt;
  &lt;style&gt;
  &lt;/style&gt;    
   &lt;body&gt;
       &lt;!-- container: to set the content's margins dealing with the responsive behaviors of the layout.--&gt;
   &lt;div class='container'&gt;
          &lt;div class='login-form col-md-4 offset-md-4'&gt;
  
                  &lt;!--jumbotron: ndicates a big box for calling extra attention to.--&gt;
                  &lt;div class='jumbotron' style='margin-top:40px; padding-top:20px;   background-color:00FF00;   font-size: 20px; width:450px'&gt; 
                      &lt;h3 align='center'&gt;SignUp&lt;/h3&gt;&lt;br&gt; 
                      &lt;?php echo $msg9;?&gt;&lt;br&gt;
  
                      &lt;!-- form: to creat form for user input
                          method=”POST” Specifying a value of POST means the browser will send the data to the web server to be processed.            
                          
                          enctype: specifies how the form-data should be encoded when submitting it to the server:
                              
                      --&gt;
                      &lt;form method='post' enctype=&quot;multipart/form-data&quot;&gt;
                        &lt;div class=&quot;form-group&quot;&gt;
                              &lt;label&gt; First Name: &lt;/label&gt;
  
                              &lt;!-- 1name: the name of th input
                                   2. placeholder: specifies a short hint that describes the expected value of a input field / textarea.
                                   3. All textual &lt;input&gt;, &lt;textarea&gt;, and &lt;select&gt; elements with class .form-control have a width of 100%.
                              --&gt;
                              &lt;input type='text' name='fname' placeholder=&quot;First Name&quot; class='form-control' value='&lt;?php echo $firstname;?&gt;'&gt;
                              &lt;!--IF the type of information provided is not the required one, this message will be displayed--&gt;
  
                              &lt;?php echo $msg;?&gt;
                              
                          &lt;!--the end of the div of First Name--&gt;
                          &lt;/div&gt;
  
                          &lt;!--start div of the Last Name--&gt;
                          &lt;div class=&quot;form-group&quot;&gt;
                              &lt;label&gt; Last Name: &lt;/label&gt;
                              &lt;input type='text' name='lname' placeholder=&quot;Last Name&quot; class='form-control'  value='&lt;?php echo $lastname;?&gt;'&gt;
                            &lt;!--IF the type of information provided is not the required one, this message will be displayed--&gt;
  
                              &lt;?php echo $msg2;?&gt;
  
                              &lt;!--the end of the div of the Last Name--&gt;
                          &lt;/div&gt;
                      
                            &lt;!--start div of the Email--&gt;
                            &lt;div class=&quot;form-group&quot;&gt;
                              &lt;label&gt; Email: &lt;/label&gt;
                              &lt;input type='email' name='mail' placeholder=&quot;Your Email&quot; class='form-control' value='&lt;?php echo $email;?&gt;'&gt;
  
                              &lt;!--IF the type of information provided is not the required one, this message will be displayed--&gt;
                              &lt;?php echo $msg3;?&gt;
  
                              &lt;!--the end of the div of the Email--&gt;
                          &lt;/div&gt;
  
                            &lt;!--start div of the birth day--&gt;
                            &lt;div class=&quot;form-group&quot;&gt;
                              &lt;label&gt; Date of Birth: &lt;/label&gt;
                              &lt;input type='date' name='dob'  value='&lt;?php echo $date;?&gt;'&gt;
                              &lt;?php echo $msg4; ?&gt;
  
                              &lt;!--the end of the div of birth day--&gt;
                           &lt;/div&gt;
  
                            &lt;!--start div of the Password--&gt;
                             &lt;div class=&quot;form-group&quot;&gt;
                                   &lt;label&gt; Password: &lt;/label&gt;
                                   &lt;input type='password' name='pass' placeholder=&quot;Password&quot; class='form-control' value='&lt;?php echo $password;?&gt;'&gt;
                                   &lt;?php echo $msg5;?&gt;
  
                                &lt;!--the end of the div of the Password--&gt;
                               &lt;/div&gt;
  
                                  &lt;!--start div of the Re-enter Password--&gt;
                                      &lt;div class=&quot;form-group&quot;&gt;
                                                   &lt;label&gt; Re-enter Password: &lt;/label&gt;
                                                  &lt;input type='password' name='cpass' placeholder=&quot;Re-enter Password&quot; class='form-control' value='&lt;?php echo $c_password;?&gt;'&gt;
                                                  &lt;?php echo $msg6;?&gt;
                                          &lt;!--the end of the div of the Re-enter Password--&gt;
                                       &lt;/div&gt;
                    
                                            &lt;!--start div of the image profile  --&gt;
                                      &lt;div class=&quot;form-group&quot;&gt;
                                                   &lt;label&gt; Profile Image: &lt;/label&gt;
                                                  &lt;input type='file' name='image'  value='&lt;?php echo $image;?&gt;'/&gt;&lt;br&gt;
                                                  &lt;?php  echo $msg7;?&gt;
  
                                                  &lt;?php  echo $msg10;?&gt;
                                          &lt;!--the end of the div of the image profile --&gt;
                                       &lt;/div&gt;
                                      
  
                                    &lt;!--start div of the checkbox  --&gt;
                                        &lt;div class=&quot;form-group&quot;&gt;
                                                   &lt;input type='checkbox' name='check'  /&gt;
                                                  I Agree the terms and conditions
                                                  &lt;?php  echo $msg8;?&gt;
  
  
                                          &lt;!--the end of the div of the checkbox --&gt;
                                       &lt;/div&gt;
  
                                          &lt;!-- submit button--&gt;
                                       &lt;br&gt;&lt;input type='submit' value='submit' name='submit'  class='btn btn-success' style=&quot;background-color:blue;&quot;&gt;&lt;br&gt;
  
                             &lt;!--the end of the form for the sign up icon--&gt;          
                          &lt;/form&gt;
  
                     &lt;!--the end of the jumbtorn class--&gt;     
                   &lt;/div&gt;
     
          &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;/body&gt; 
  &lt;/html&gt;
  </code></pre>
  <p>I have rewritten the part of the code here where the problem could be.</p>
  <pre><code> // this part is from php
  else
  {
  
      $img_ext=explode(&quot;.&quot;,$image);
      $image_ext=$img_ext['1'];
      if($image_ext=='jpg' || $image_ext=='png' || $image_ext=='PNG' || $image_ext=='JPG' || $image_ext=='jpeg' || $image_ext=='JPEG' )
      {
          
          // to conection to the  database and gives the values    
          mysqli_query($con, &quot;INSERT INTO users(first_name,last_name,mail,password,dob,img)
          VALUES ('$firstname', '$lastname','$email','$date','$password','$image')&quot;);
  
          $msg9=&quot;&lt;div class='success'&gt; You are Successfully Registered &lt;/div&gt;&quot;;
          $firstname='';$lastname='';$email='';$date='';$password='';$c_password='';$image='';
      }
  
          else
             {
             $msg7=&quot;&lt;div class='error'&gt; Please Upload an Image File&lt;/div&gt;&quot;;
             }
  
       }
    
  </code></pre>
  <p>This part is from body.</p>
  <p>I have rewritten the part of the code here where the problem could be.</p>
  <pre><code>          &lt;!--start div of the image profile  --&gt;
                                      &lt;div class=&quot;form-group&quot;&gt;
                                                   &lt;label&gt; Profile Image: &lt;/label&gt;
                                                  &lt;input type='file' name='image'  value='&lt;?php echo 
                                                  $image;?&gt;'/&gt;&lt;br&gt;
                                                  &lt;?php  echo $msg7;?&gt;
  
                                                  &lt;?php  echo $msg10;?&gt;
                                          &lt;!--the end of the div of the image profile --&gt;
                                       &lt;/div&gt;
  </code></pre>