PHP mysql, update record fails but no error

Lars Eriks

PHP mysql, update record fail but no error.

$sql = "UPDATE users SET password='$new_password' WHERE email='$email' AND id='$uId'";

//if ($mysqli->query($sql)) also result in True
if ($mysqli->query($sql) === TRUE) {  
    $_SESSION['test6'] = $mysqli->error;  
    $_SESSION['message'] = "Your  password have been updated!";  
    header("location:gain.php");  
    }  
else {  
    $_SESSION['test7'] = "Error updating record: " . $mysqli->error;  
  }  

I know why it don’t update, incorrect values in the WHERE clause. If the values are correct it updates just fine. But no errors to be seen anywhere when it fails, with or without a successful update the $mysqli->query($sql) are true.

How to catch the error?
I'm new to this, and I should probably look into PDO or what it's called, but shouldn't mysqli give an error of some sort? This is on a XAMPP localhost.

Matt Clark

You don't get an error, because there was no error, your search criteria just did not match any results. If you want to get the number of rows affected by the query, do just that, use affected_rows().

$updated = $mysqli->affected_rows();

if ( $updated == 0 ) {
    echo "None were updated!";
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

php update MySql record

Update BLOB in record with PHP and MySQL

PHP & MYSQL, update record that is an exact match

SQL UPDATE works in MySQL fails in PHP

Cannot add or update a child row: a foreign key constraint fails Error in PHP or MySQL?

Update record number unexpectedly fails

MySQL update trigger error; setting a value in an updated record

PHP / MySQL: How to return info if record already exists (without update)

Update query make record empty from MySQL in Codeigniter PHP

Php mysql update to same record value and fix with round function

Php fails to update Date in MySQL table via HTML form

PHP MySQL update with multiple WHERE (syntax error)

Android PHP PDO MySQL UPDATE Syntax Error

PHP MYSQL - insert a new record but requires column from select statement in another table - fails in php

Inserting data when no record is found else update the previous record with last inserted ID using PHP Mysql

MySQL update only one record

MySQL trigger on Delete, update a record?

MySQL select last record and update it

Update sql record by checkbox in php

Laravel -request fails mySQL update

CQLSH : NoHostAvailable error Cassandra update fails update

PHP Update MySQL from CSV Skip Row on Error

Php mysql query update of data gives syntax error

MySQL ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails

Error Code: 1452. Cannot add or update a child row: a foreign key constraint fails - MYSQL

MySQL Error Code: 1452. Cannot add or update a child row: a foreign key constraint fails

How to resolve MySQL error "Cannot delete or update a parent row: a foreign key constraint fails"?

mysql: ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails

MySQL Workbench: Error Code 1452. Cannot add or update a child row: a foreign key constraint fails