Reputation: 39
I'm trying to understand where I am wrong with this query..
$query = "INSERT INTO turni (data, utenteId, turno_ceduto, tipo_turno_ceduto,
turno_cercato,
note, date) VALUES (?, ?, ?, ?, ?, ?, NOW())";
$stmt = mysqli_prepare($dbc,$query);
mysqli_stmt_bind_param($stmt,'sissss', $data, $utenteId, $turno_ceduto,
$tipo_turno_ceduto, $turno_cercato, $note);
mysqli_stmt_execute($stmt);
$count = mysqli_stmt_affected_rows($stmt);
Why is $count -1??
Upvotes: 0
Views: 47
Reputation: 562240
You should always check for errors after each prepare() and execute(), and report the errors.
Here's an example:
if (($stmt = mysqli_prepare($dbc,$query)) === false) {
trigger_error(mysqli_error($dbc), E_USER_ERROR);
}
mysqli_stmt_bind_param($stmt,'sissss', $data, $utenteId, $turno_ceduto,
$tipo_turno_ceduto, $turno_cercato, $note);
if (mysqli_stmt_execute($stmt) === false) {
trigger_error(mysqli_stmt_error($stmt), E_USER_ERROR);
}
$count = mysqli_stmt_affected_rows($stmt);
Upvotes: 0
Reputation: 15454
Question
Why is $count -1??
Answer
-1 indicates that the query has returned an error
You shoud check errors with mysqli_error, it's returns a string description of the last error.
You get the error description from the last mysqli-function, not from the last mysql-error.
Upvotes: 1