im making a form on php which saves data into the database here is the code for it where i send data from php form to the database:
<?php
$users_name = $_POST['name'];
$users_email = $_POST['email'];
$users_phoneNumber = $_POST['phNo'];
$users_cnic = $_POST['cnic'];
$users_voucherNumber = $_POST['vNum'];
$users_modelNumber = $_POST['prod'];
if( $_POST )
{
$dbhost = "localhost";
$dbuser = "root";
$dbpassword = "";
$dbname = "dany";
$query = "";
$sqlQuery = "";
$conn = new mysqli($dbhost, $dbuser, $dbpassword, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo ("Variables values: " . " " . $users_cnic . " " .
$users_phoneNumber . "<br>");
$query = "INSERT INTO customer( c_name, c_phoneNumber, c_cnic,
c_email, c_voucherNumber, c_modelNumber) VALUES
('$users_name','$users_phoneNumber', '$users_cnic',
'$users_email', $users_voucherNumber,
'$users_modelNumber')";
if ($conn->query($query) === TRUE) {
//if successful
echo ("Variables values after success: " . " " . $users_cnic .
" " . $users_phoneNumber . "<br>");
} else {
//if data not successfully entered
echo "Error: " . $query . "<br>" . $conn->error;
}
$conn->close();
}
?>
but the problem is when i try to send data, same value for "c_phoneNumber" and "c_cnic" is sent every single time which is "2147483647". i.e every row in the table has two columns and each of this column has value "2147483647".
if you see the line which i have witten to check the values if they are correct:
echo ("Variables values: " . " " . $users_cnic . " " . $users_phoneNumber .
"<br>");
here they have the values exactly the same as sent from the textboxes of the form. but when the query is made in the very next line of code:
$query = "INSERT INTO customer( c_name, c_phoneNumber, c_cnic,
c_email, c_voucherNumber, c_modelNumber) VALUES
('$users_name','$users_phoneNumber', '$users_cnic',
'$users_email', $users_voucherNumber,
'$users_modelNumber')";
both these variables hold "2147483647".
and when the if statment runs after successfully entering the data into table:
if ($conn->query($query) === TRUE) {
//if successful
echo ("Variables values after success: " . " " . $users_cnic .
" " . $users_phoneNumber . "<br>");
}
it has the same values which have been passed from the text boxes. i cannot figure out the problem the variable data remains the same throughout the programs running state but when inserted into the database changes.
i have tried:
1- creating a new table
2- creating two new columns
3- sending hard coded values.
$query = "INSERT INTO customer( c_name, c_phoneNumber, c_cnic,
c_email, c_voucherNumber, c_modelNumber) VALUES
('$users_name',123, 456,
'$users_email', $users_voucherNumber,
'$users_modelNumber')";
and when i do this step no 4, the values are perfectly send and inserted which are 123, 456.
4- creating a new query, saving it in an other variable, running the query = same results.(error)
2147483647 is the max (signed) value for an INT field in MySQL. Any number larger than that will be reset to that max value. See https://dev.mysql.com/doc/refman/5.7/en/integer-types.html. You can use the BIGINT
type if you need to store bigger numbers.