This is something that we have been banging our heads over for almost a week now.
What's happening?
In our application we have a field for telephone number, which relates to a database field with data-type VARCHAR(25). WE ARE NOT USING INT,BIGINT.
On form submission we are storing the data as following.
$_POST
sanitize data using
filter_input(INPUT_POST, 'mobile', FILTER_SANITIZE_STRING);
Using
mysqli->prepare
to insert the data into database, where the bind-params are also properly set. This field is set to map with "s" (string).Data is then stored into the DB.
Now we are logging all these values in a separate log files as we were debugging the issue. The most strange this has been discovered while looking at log files. It seems that the data correctly came when sent via POST, was still good after sanitation, was still good when it was retrieved immediately after insertion into the DB. But when the same value was fetched by our frontend application to be displayed to the user-end, the data fetched was 2147483647.
This issue doesn't happen with all such insertion, it happens very randomly, and rarely, but has brought us to a point, where I am pulling my hair-out to find a solution.
Development Platform information: PHP 5.3, MySQL 5.5.31
Any help would be greatly appreciated.
Code
Here's the code:
$Mobile = filter_input(INPUT_POST, 'mobile', FILTER_SANITIZE_STRING);
$stmt = $mysqli->prepare("INSERT INTO enquiry(idAdminUsers, isConverted, Firstname, Lastname , Residence , WorkCollege , Gender , Age , Occupation , Mobile , Email , Transport , FirstMile , LastMile , Commute , NoPublicTransport , Member , YesMember , PurposeMember , NoMember , Note, Date, FirstMileCost, FirstMileTime, LastMileCost, LastMileTime, landlineNumber) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW(),?,?,?,?,?)");
if ($stmt) {
if ($stmt->bind_param('iisssssissssssssisssssssss', $idAdminUsers, $isConverted, $firstName, $lastName, $Residence, $WorkCollege, $Gender, $Age, $Occupation, $Mobile, $Email, $Transport, $FirstMile, $LastMile, $Commute, $NoPublicTransport, $Member, $YesMember, $PurposeMember, $NoMember, $Note, $FirstMileCost, $FirstMileTime, $LastMileCost, $LastMileTime, $landlineNumber)) {
$stmt->execute()'
as soon as it is inserted the retrieval happens by following
$stmt = $mysqli->prepare("SELECT idEnquiry , idAdminUsers , isConverted , Firstname , Lastname , Residence , WorkCollege , Gender , Age , Occupation , Mobile , Email , Transport , FirstMile , LastMile , Commute , NoPublicTransport , Member , YesMember , PurposeMember , NoMember , Note, Date, FirstMileCost, FirstMileTime, LastMileCost, LastMileTime, landlineNumber FROM enquiry WHERE idEnquiry = ?");
if ($stmt) {
if ($stmt->bind_param('i', $idEnquirySelect)) {
if ($stmt->execute()) {
this is getting logged, and shows that the data was correctly entered. But as soon as we go and check in the database very randomly data is incorrect.
Following is the Database table create script:
CREATE TABLE IF NOT EXISTS `enquiry` (
`idEnquiry` int(11) NOT NULL AUTO_INCREMENT,
`Firstname` varchar(255) DEFAULT NULL,
`Mobile` varchar(25) DEFAULT NULL,
`Email` varchar(45) DEFAULT NULL,
`Age` int(16) DEFAULT NULL,
`idAdminUsers` int(11) DEFAULT NULL,
`Member` tinyint(4) DEFAULT NULL,
`isConverted` tinyint(4) DEFAULT NULL,
`Note` text,
`Residence` varchar(255) DEFAULT NULL,
`WorkCollege` varchar(255) DEFAULT NULL,
`Transport` varchar(31) DEFAULT NULL,
`FirstMile` varchar(31) DEFAULT NULL,
`LastMIle` varchar(31) DEFAULT NULL,
`Gender` varchar(8) DEFAULT NULL,
`Commute` text,
`NoPublicTransport` varchar(64) DEFAULT NULL,
`YesMember` varchar(255) DEFAULT NULL,
`PurposeMember` varchar(128) DEFAULT NULL,
`NoMember` varchar(128) DEFAULT NULL,
`Occupation` varchar(64) DEFAULT NULL,
`Lastname` varchar(255) DEFAULT NULL,
`Date` date DEFAULT NULL,
`FirstMileCost` varchar(45) DEFAULT NULL,
`FirstMileTime` varchar(45) DEFAULT NULL,
`LastMileCost` varchar(45) DEFAULT NULL,
`LastMileTime` varchar(45) DEFAULT NULL,
`landlineNumber` varchar(15) NOT NULL,
PRIMARY KEY (`idEnquiry`),
UNIQUE KEY `idenquiry_UNIQUE` (`idEnquiry`),
UNIQUE KEY `Email_UNIQUE` (`Email`),
KEY `idAdminUserFK_idx` (`idAdminUsers`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='All the enquiry details are added to this table.' AUTO_INCREMENT=482 ;