MySql UPDATE command not detecting errors
Posted: Mon Dec 22, 2014 10:41 am
Hi, I have just become aware that the MySql UPDATE command is not returning an error if I force the command to try and update a record that is not on file. The experimental code I am using to try to catch the error is below. Using the NetBeans debugger to look at the values, I complete an UPDATE command with a valid record key then I force the record key to 9999 that does not exists. The error related fields return exactly the same values even with the submission of 9999. I have tried a variety of ways to catch the error with no luck. I checked the syntax and all looks well. The exact same types of checks (the ones with the error handler below) catch a SELECT trying to get a record not on file. I suspect the same problem is occurring with the INSERT command if I try to insert a record that already exists. I am using XAMPP with PHP 5.5.11. I am using MyIsam. I am stumped for what to check next. Does anyone have any ideas.
Thanks,
John
Thanks,
John
Code: Select all
$MyString = "
SELECT
tblMemberMaster.fldMM_Key,
tblMemberMaster.fldMM_User_ID
FROM
tblMemberMaster;
";
$result = @mysqli_query($con,$MyString);
if (!$result) {
trigger_error("Error" . mysqli_error($con),E_USER_ERROR);
}
while($row = mysqli_fetch_array($result)) {
$fldMM_Key = $row['fldMM_Key'];
$fldMM_User_ID = $row['fldMM_User_ID'];
$sql = "
UPDATE
tblMemberMaster
SET
fldMM_User_ID = '$fldMM_User_ID'
WHERE
fldMM_Key='$fldMM_Key';
";
if (!mysqli_query($con, $sql)) {
$ResultMessage = "Error updating member file. " . mysqli_error($con);
trigger_error($ResultMessage,E_USER_ERROR);
}
$MyErrorDesc = mysqli_sqlstate($con); //Contains 00000
$MyErrorNumber = mysqli_errno($con); //Contains 0
$sql = "
UPDATE
tblMemberMaster
SET
fldMM_User_ID = '$fldMM_User_ID'
WHERE
fldMM_Key='9999';
";
if (!mysqli_query($con, $sql)) {
$ResultMessage = "Error updating member file. " . mysqli_error($con);
trigger_error($ResultMessage,E_USER_ERROR);
}
$MyErrorDesc = mysqli_sqlstate($con); //Contains 00000
$MyErrorNumber = mysqli_errno($con); //Contains 0
} //End of the while loop.