我试图将手机号码插入数据库但不是手机号码,而是保存为2147483647

时间:2016-07-30 16:45:38

标签: php mysql sql html5

我的PHP代码是...... 代码工作正常的信息存储在数据库中,但唯一的问题是 无论我在表单中给出的10位数字,mob_number以及pmob_number都会将数据存储为2147483647。请帮帮我..谢谢你: - )

     <?php 
       $servername = "localhost";  
       $username = "root";  
       $password = "";  
       $conn = mysqli_connect ($servername , $username , $password) or die("unable to connect to host");  
       $sql = mysqli_select_db ($conn,'vcet') or die("unable to connect to database"); 




 //code to insert into db...
 $user_name=$_POST['user_name']; 
 $roll_number=$_POST['roll_number'];
 $user_batch=$_POST['user_batch'];
 $user_from=$_POST['user_from'];
 $user_year=$_POST['user_year'];
 $user_level=$_POST['user_level'];
 $email_id=$_POST['email_id'];
 $F_name=$_POST['F_name'];
 $m_name=$_POST['m_name'];
 $g_name=$_POST['g_name'];
 $mob_number=$_POST['mob_number'];
 $addressline1=$_POST['addressline1'];
 $addressline2=$_POST['addressline2'];
 $city=$_POST['city'];
 $pmob_number=$_POST['pmob_number'];







 $land_number=$_POST['land_number'];
 $cutoff=$_POST['cutoff'];
 $dept=$_POST['dept'];
 $medium = $_POST['medium'];
 $locality=$_POST['locality'];
 $intrest=$_POST['intrest'];
 $scholar=$_POST['scholar'];
 $income=$_POST['income'];
 $user_caste=$_POST['user_caste'];
 $user_admit=$_POST['user_admit'];
 $user_stay=$_POST['user_stay'];



if (!filter_var($email_id, FILTER_VALIDATE_EMAIL)) {
   echo  "Invalid email format"; 
}    else
{
    //executes the rest of the code





    if(!preg_match('/^\d{10}$/',$pmob_number)) // phone number is valid
    {

       echo "Phone number invalid !";

    }
    else // phone number is  valid
    {














        $msg="";


        $num_length = strlen((string)$pmob_number);

        if($num_length!=10){
            echo "Enter a valid number";


         }else
{





 $user_info = "INSERT INTO studentinfo"."     (user_name,roll_number,user_batch,user_from,user_year,user_level,email_id,F_name,m_name,g_name,mob_number,addressline1,addressline2,city,pmob_number,land_number,cutoff,dept,medium,locality,intrest,scholar,income,user_caste,user_admit, user_stay)". "VALUES ('$user_name', '$roll_number','$user_batch','$user_from','$user_year','$user_level','$email_id','$F_name','$m_name','$g_name','".$mob_number."','$addressline1','$addressline2','$city','$pmob_number','$land_number','$cutoff','$dept','$medium','$locality','$intrest','$scholar','$income','$user_caste','$user_admit','$user_stay')"; 
 if (!mysqli_query($conn,$user_info)) { die('Error: ' .   mysqli_error($conn)); } echo "Your information was added to the database."; 
 mysqli_close($conn); 
 }

}

}
 ?> 

1 个答案:

答案 0 :(得分:3)

  

我试图将手机号码插入数据库但不是手机号码,而是保存为2147483647

看起来您的数据库架构错误了。确保您将电话号码数据放入的列不是字符串类型(即VARCHAR),而不是数字(不是INTEGER,{{ 1}},BIGINT等)