I’m stuck on this problem and all error examples are using $stmt->error or something which I don’t understand. I write in procedural style not OOP. My insert fails so I’m curious to debug it please…
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_USER_PASSWORD, DB_NAME) or die(DB_CONNECT_ERROR);
if (!$stmt = mysqli_prepare($dbc, $query)) die('SEL:mysqli_prepare');
call_user_func_array('mysqli_stmt_bind_param', array_merge(array($stmt, 'sssssssssssssssssssssbsssss')), $idb);
mysqli_stmt_execute($stmt);
if (!mysqli_stmt_affected_rows($stmt)) {
// Failed to insert
} else {
// Success
}
My insert fails… how can I see what the reason was? Please and thank you in advance! I’m also just learning prepared statements so if I did something wrong please advise… The code makes it down to the // FAILED TO INSERT line and when checking cpanel the query did fail (there was nothing in the DB).
If you want to write your own example using the style of programming I used above and show me how to check if an insert failed that’s cool too. Once I see how you do yours I can change my code. 🙂
Use
mysqli_stmt_error()andmysqli_stmt_errno()to retrieve the error information:Note
I would recommend you to use
instead of relying on the ugly autocast feature of PHP