title: MYSQL only runs query if number is 6 digits long when its INT(11) PHP
body: <p>Right, I have an upload form. When submit it should store all the input fields into the database phpmyadmin. Also it should create a folder for the attachments to save into in a folder on the local server.</p>
  <p>If there are no errors in the form validation it does the above. What is actually happening is that the folder is getting created in the correct folder holding the attachment documents. But the details are not saving into the database as when I look on phpmyadmin there is nothing there.</p>
  <p>The only time the database query runs is when the  contains 6 digits. If it contains 11 numbers it doesnt run. But heres the weird thing if i put in 7 digits the query does run but it saves in the database as 6 digits and deleted the first digit.</p>
  <p>HTML:</p>
  <pre><code>  &lt;form action=&quot;upload.php&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
          Select your policy type:&lt;br/&gt;
          &lt;select name=&quot;pol_type&quot;&gt; 
              &lt;option selected=&quot;selected&quot; value=&quot;Private Car&quot;&gt;Private Car&lt;/option&gt;
              &lt;option value=&quot;Commercial Vehicle&quot;&gt;Commercial Vehicle&lt;/option&gt;
              &lt;option value=&quot;Motorcycle&quot;&gt;Motorcycle&lt;/option&gt;   
          &lt;/select&gt;&lt;br/&gt;&lt;br/&gt;
          Customer reference&lt;br/&gt;
          &lt;input type=&quot;text&quot; name=&quot;reference&quot;/&gt;&lt;br/&gt;&lt;br/&gt;
          First Name&lt;br/&gt;
          &lt;input type=&quot;text&quot; name=&quot;first_name&quot;/&gt;&lt;br/&gt;&lt;br/&gt;
          last Name&lt;br/&gt;
          &lt;input type=&quot;text&quot; name=&quot;last_name&quot;/&gt;&lt;br/&gt;&lt;br/&gt;
          Vehicle registration&lt;br/&gt;
          &lt;input type=&quot;text&quot; name=&quot;registration&quot;/&gt;&lt;br/&gt;&lt;br/&gt;
          Contact Number&lt;br/&gt;
          &lt;input type=&quot;text&quot; name=&quot;number&quot;/&gt;&lt;br/&gt;&lt;br/&gt;
          Email Address&lt;br/&gt;
          &lt;input type=&quot;text&quot; name=&quot;email&quot;/&gt;&lt;br/&gt;&lt;br/&gt;
          Upload Your documents &lt;br/&gt;                                                  
          &lt;input type=&quot;file&quot; name=&quot;pictures[]&quot; /&gt;&lt;br/&gt;&lt;br/&gt;
          &lt;input type=&quot;file&quot; name=&quot;pictures[]&quot; /&gt;&lt;br/&gt;&lt;br/&gt;
          &lt;input type=&quot;file&quot; name=&quot;pictures[]&quot; /&gt;&lt;br/&gt;&lt;br/&gt;
          &lt;input type=&quot;submit&quot; value=&quot;Send&quot; /&gt;
          
      &lt;/form&gt;
  </code></pre>
  <p>Upload.php:</p>
  <pre><code>&lt;?php
  session_start();
  $_SESSION['errors'] = array();
  require_once(&quot;includes/db_connection.php&quot;);
  require_once(&quot;includes/functions.php&quot;);
      
      $errors = array();
  
      //Variables from $_POST
          $ref = $_POST['reference'];
          $type = $_POST['pol_type'];
          $first_name = $_POST['first_name'];
          $last_name = $_POST['last_name'];
          $reg = $_POST['registration'];
          $number = $_POST['number'];
          $email = $_POST['email'];    
  
      //Validations:
          //1) There needs to be at least one upload
          $total_files = count(array_filter($_FILES['pictures']['name']));
          if($total_files &lt; 1)
          {
              $_SESSION['errors'][] = &quot;No files have been uploaded!&quot;;
          }
          //2) Reference needs to be certain length
          if(strlen($ref) &lt; 7)
          {
              $_SESSION['errors'][] = &quot;client reference cannot be empty, and must be 8 characters long&quot;;
          }
          //3) All Fields need to be filled
          if($type == &quot;&quot; || $first_name == &quot;&quot; || $last_name == &quot;&quot; || $reg == &quot;&quot; || $number == &quot;&quot; || $email == &quot;&quot;){
              $_SESSION['errors'][] = &quot;All Fields must have a value!&quot;;
          }   
          //3) Files size limit to 20MB
          $total_size = 0;
          foreach ($_FILES[&quot;pictures&quot;][&quot;size&quot;] as $size) 
          {
              $total_size = $total_size + $size;  
          }        
              if($total_size &gt; 1e+7)
              {
                  $_SESSION['errors'][] = &quot;File size limit is 20MB, your files are too big!&quot;;
              }
          
          
  // If there are no errors in the validation then continue with script
  if(empty($_SESSION['errors']))
  {
  
      
      
      $img_count = 0;
      $img_name1 = &quot;&quot;;
      $img_name2 = &quot;&quot;;
      $img_name3 = &quot;&quot;;
              //Foreach files uplaoded place the file name into variable to go into table for later reference.
              foreach ($_FILES[&quot;pictures&quot;][&quot;name&quot;] as $key =&gt; $Name) 
              {
                  $img_count++;
                      if($img_count == 1)
                      {
                          $img_name1 = $_FILES[&quot;pictures&quot;][&quot;name&quot;][$key];     
                      }elseif($img_count == 2)
                      {
                          $img_name2 = $_FILES[&quot;pictures&quot;][&quot;name&quot;][$key];
                      }else
                      {
                          $img_name3 = $_FILES[&quot;pictures&quot;][&quot;name&quot;][$key];
                      }  
              }   
      $query =  &quot;INSERT INTO &quot;;
      $query .= &quot;customers&quot;;  
      $query .= &quot;(`reference`, `policy_type`, `first_name`, `last_name`, `registration`, `number`, `email`, `doc1`, `doc2`, `doc3`) &quot;;
      $query .= &quot;VALUES ('{$ref}', '{$type}', '{$first_name}', '{$last_name}' , '{$reg}' , '{$number}' , '{$email}' , '{$img_name1}' , '{$img_name2}' , '{$img_name3}')&quot;;
      $result = mysqli_query($connection, $query);
      if(!$result){
          die('Invalid query: ' . mysql_error());
      }
  
      $target_dir = &quot;docs&quot;.DIRECTORY_SEPARATOR;
      //IF/ELSE the folder is already created...
          if(!file_exists($target_dir . $ref . DIRECTORY_SEPARATOR))
          {//Create folder named 1 inside the customer ref folder.
              mkdir($target_dir . $ref . DIRECTORY_SEPARATOR . &quot;1&quot; . DIRECTORY_SEPARATOR, 0775, true);
              $count = 0;
          }else
          {//Create new folder inside customer ref folder 
              //count the amount of folders inside docs/$ref/
              $find_folders = glob($target_dir . $ref . DIRECTORY_SEPARATOR . &quot;*&quot;,GLOB_ONLYDIR);
              $count = count($find_folders);
              //create new folder inside $ref/ using count+1 to make the folder increase by 1
                  $new_folder = $count +1;
                  mkdir($target_dir . $ref . DIRECTORY_SEPARATOR . $new_folder . DIRECTORY_SEPARATOR, 0775, true);        
          }
                  //IF count exists then the $target_file changes to the new folder...
                      if($count &gt; 0)
                          {
                              $target_file = $target_dir . $ref . DIRECTORY_SEPARATOR . $new_folder . DIRECTORY_SEPARATOR;  
                          }else
                          {//else use first directory
                              $target_file = $target_dir . $ref . DIRECTORY_SEPARATOR . &quot;1&quot; . DIRECTORY_SEPARATOR;
                          }
      //Loop through files and place them into $target_file...
          foreach ($_FILES[&quot;pictures&quot;][&quot;name&quot;] as $key =&gt; $Name) 
          {
                  $tmp_name = $_FILES[&quot;pictures&quot;][&quot;tmp_name&quot;][$key];
                  $name = $_FILES[&quot;pictures&quot;][&quot;name&quot;][$key];
                  move_uploaded_file($tmp_name, $target_file . &quot;$name&quot;);
          }
          redirect_to('thanks.php');
          
  }else//if there are errors in validation then redirect to index and show them
  {
      redirect_to('index.php');
  }//END OF empty session
  
  
  
      
  ?&gt;
  </code></pre>
  <p>The db_connection is correct that I include at the top of upload.php</p>
  <p>This is my table on phpmyadmin:</p>
  <p><img src="https://i.stack.imgur.com/wLDuS.jpg" alt="enter image description here" /></p>
  <p>Does any one know why the data is not going into my phpmyadmin database table?</p>
  <p><strong>EDIT:</strong></p>
  <p>When i print the query i get this:
  INSERT INTO customers(<code>reference</code>, <code>policy_type</code>, <code>first_name</code>, <code>last_name</code>, <code>registration</code>, <code>number</code>, <code>email</code>, <code>doc1</code>, <code>doc2</code>, <code>doc3</code>) VALUES ('8888888', 'Private Car', 'Matthew', 'Smart' , 'Kp09 JVL' , '07707783196' , 'mattysmart' , 'logo.jpg' , '' , '')</p>
  <p>and now when i try to do it on phpmyadmin without running it through php i get the following error:</p>
  <h1>1264 - Out of range value for column 'number' at row 1</h1>