title: why this sql query inserting garbage value in the database instead of the number value [POST method]
body: <p>I am working on this form but it's stroing garbage value of the 'phone' field in the database where I am giving the right number. what's wrong in the code? First i set the length of that field to 11 and thought that could be the problem. but when I increased that to even 50 the same problem occurred again. How to solve this? </p>
  
  <p>PS: neglect the security part of the form, it's just for testing purpose.</p>
  
  <pre><code>&lt;table border="1" id="tab1"&gt;
  &lt;form action="create.php" method="POST" enctype="multipart/form-data"&gt;
  
      &lt;tr align='center'&gt;&lt;td&gt;Ad Title:&lt;/td&gt;&lt;td&gt;&lt;input type='text' name='ad_title' id="ad_title" placeholder='type ad title'/&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr align='center'&gt;&lt;td&gt;Ad Description:&lt;/td&gt;&lt;td&gt;&lt;textarea name='ad_details' id="ad_details" placeholder='type ad details' cols="40" rows="10"&gt;&lt;/textarea&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr align="center"&gt;&lt;/tr&gt;
      &lt;tr align="center"&gt;&lt;td&gt;Category:&lt;/td&gt;&lt;td&gt;
          &lt;select name="category"&gt;
              &lt;option value="mobile"&gt;Mobile Phone&lt;/option&gt;
              &lt;option value="computer"&gt;Computer&lt;/option&gt;
              &lt;option value="book"&gt;Books&lt;/option&gt;
              &lt;option value="fashion"&gt;Fashion and Beauty&lt;/option&gt;
          &lt;/select&gt;
      &lt;/td&gt;&lt;/tr&gt;
      &lt;tr align='center'&gt;&lt;td&gt;Phone Number:&lt;/td&gt;&lt;td&gt;&lt;input type='number' id="phone" name='phone' placeholder='type your Phone Number'/&gt;&lt;/td&gt;&lt;/tr&gt;
  
      &lt;tr align='center'&gt;&lt;td&gt;Email:&lt;/td&gt;&lt;td&gt;&lt;input type='text' name='email' id="email" placeholder='type your email'/&gt;&lt;/td&gt;&lt;/tr&gt;
  
      &lt;tr align='center'&gt;&lt;td&gt;Price:&lt;/td&gt;&lt;td&gt;&lt;input type='text' name='price' id="price" placeholder='enter your desired Price'/&gt;&lt;/td&gt;&lt;/tr&gt;
  
      &lt;tr align="center"&gt;&lt;td&gt;Negotiable:&lt;/td&gt;&lt;td&gt;&lt;input type="radio" name="nego" value="yes"/&gt;YES&lt;input type="radio" name="nego" value="no"/&gt;NO&lt;/td&gt;&lt;/tr&gt;
  
      &lt;tr align="center"&gt;&lt;td&gt;City/Town:&lt;/td&gt;&lt;td&gt;
          &lt;select name="city"&gt;
              &lt;option value="Jalpaiguri"&gt;Jalpaiguri&lt;/option&gt;
              &lt;option value="Siliguri"&gt;Siliguri&lt;/option&gt;
          &lt;/select&gt;
      &lt;/td&gt;&lt;/tr&gt;
  
      &lt;tr align='center'&gt;&lt;td&gt;Location:&lt;/td&gt;&lt;td&gt;&lt;input type='text'  id="location" name='location' placeholder='type your Location'/&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Choose Photo for Ad:&lt;/td&gt;&lt;td&gt;&lt;input type='file' name='ad_pic'/&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr align='center'&gt;&lt;td colspan="7"&gt;&lt;input type='submit' id="submit" name ='submit' value='Create Ad'/&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;/form&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>the php code is as follows:</p>
  
  <pre><code>&lt;?php
  
  session_start();
  
  if(!isset($_SESSION['username'])){
      header("location:login.php");
  }
  
  $user  = $_SESSION['username'];
  
  $conn = new mysqli("localhost","root","","pending");
  
      if($conn-&gt;connect_error){
          echo "&lt;script&gt;document.getElementById('noti').innerHTML='Database Error.Please Try again !';&lt;/script&gt;";
      }
  
  if(isset($_POST['submit'])){
  
      $ad_title = $_POST["ad_title"];
      $ad_details = $_POST["ad_details"];
      $category = $_POST["category"];
      $phone = $_POST["phone"];
      $email = $_POST["email"];
      $nego = $_POST["nego"];
      $city = $_POST["city"];
      $location = $_POST["location"];
      $price = $_POST["price"];
  
  $sql = $conn-&gt;query("INSERT INTO ads(ad_id,user_name,ad_title,ad_details,price,category,phone,email,negotiable,city,location) VALUES('','$user','$ad_title','$ad_details','$price','$category','$phone','$email','$nego','$city','$location')");
  
  $pid = $conn-&gt;insert_id;
  
  $newname = "$pid.jpg";
  
  move_uploaded_file($_FILES['ad_pic']['tmp_name'], "ad_images/$newname");
  }
  </code></pre>
  
  <p>?></p>