P粉5384621872023-09-02 11:56:45
As of PHP 8.1, the default setting for mysqli error reporting is MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT, which causes errors to throw exceptions instead of just returning false
.
If you want to check for errors in your code instead of getting exceptions, use
mysqli_report(MYSQLI_REPORT_OFF);
A better solution is to use exception handlers.
if ($conn) { $sql = "INSERT INTO tbl_users (userId, email, pass) VALUES ('$userId', '$email', '$pass')"; try { mysqli_query($conn, $sql); echo json_encode(array( "status" => "Ok", "message" => "Success", )); catch (mysqli_sql_exception $e) { echo json_encode(array( "status" => "Error", "message" => $e->getMessage() )); } }