2016-07-30 86 views
-2

我的php代碼是... 該代碼工作正常的信息獲取存儲在數據庫中,但唯一的問題是, mob_number以及pmob_number將商店作爲2147483647存儲在數據庫服務器中,而不管我在表單中給出的10位數字是什麼。請幫我..Thanks提前:-)我正試圖插入手機號碼到數據庫,而不是手機號碼,它被保存爲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); 
} 

} 

} 
?> 
+2

這似乎是「一把手」的類型是一個4字節的整數,而不是一個字符串。 –

+0

顯示一個明確的樣本 – scaisEdge

+1

一些合理的代碼縮進將是一個好主意。它可以幫助我們閱讀代碼,更重要的是,它可以幫助您**調試您的代碼** [快速瀏覽編碼標準](http://www.php-fig.org/psr/psr-2/ )爲了您自己的利益。您可能會被要求在幾周/幾個月內修改此代碼 ,最後您會感謝我。 – RiggsFolly

回答

2

我真的試圖插入手機號碼到數據庫中,但不是它保存爲2147483647

它看起來的手機號碼比如你的數據庫模式錯誤。確保列你把你的電話號碼數據到相當的類型(即VARCHAR)和數字(不INTEGERBIGINTDECIMAL等)

+0

非常感謝你長期以來一直困在這裏。@ Marcin –