Raj Crk Raj Crk - 4 months ago 7
SQL Question

I`m trying to insert mobile number into database but instead of the mobile number it is saved as 2147483647

My php code is ...
The code works fine information gets stored on the database but the only problem is that
The mob_number as well as pmob_number gets stores as 2147483647 in the database server no matter what 10 digit number i give in the form . please help me out ..Thanks in Advance :-)

<?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);
}

}

}
?>

Answer

I`m trying to insert mobile number into database but instead of the mobile number it is saved as 2147483647

It looks like you got your database schema wrong. Ensure column you put your phone number data into is rather of string type (i.e. VARCHAR), not numeric (not INTEGER, BIGINT, DECIMAL etc)

Comments