0

I am attempting to update a MySQL database table with new rows from a PHP script. The script is called from a frontend HTML form that gets seralised and passed to the PHP as $_POST variables.

    $stmt = $con->prepare("UPDATE blog SET tag = ?, datestamp = ?, title = ?, content = ?, views = ?, shares = ? WHERE id=?");
    $stmt->bind_param("ssssiii", $tag, $datestamp, $title, $content, $views, $shares, $postid);
    $stmt->execute();

    / Check whether the execute() succeeded 
    if ($stmt->errno) {
        echo "FAILURE! " . $stmt->error;
    }
    else {
        echo var_dump($stmt);
        printf("%d Row updated.\n", $stmt->affected_rows); 
    }

The request does not throw am error, but the database row does not get updated, and it outputs "0 Rows updated". The serialised data is being sent as the right types (strings and ints where appropriate). Does anyone know what might be causing the issue?

echo var_dump($stmt) returns :

object(mysqli_stmt)#2 (9) { ["affected_rows"]=> int(0) ["insert_id"]=> int(0) ["num_rows"]=> int(0) ["param_count"]=> int(7) ["field_count"]=> int(0) ["errno"]=> int(0) ["error"]=> string(0) "" ["sqlstate"]=> string(5) "00000" ["id"]=> int(1) }
  • Post an example of what the echo var_dump($stmt); will return. – Racil Hilan Oct 30 '15 at 22:03
  • Hi Racil, I've edited the post to clarify. – James Milner Oct 30 '15 at 22:05
  • OK, what is the value of $postid? And can you confirm that this value exists in the database? – Racil Hilan Oct 30 '15 at 22:08
  • / Check whether the execute() succeeded is that a typo? – Akshay Oct 30 '15 at 22:08
  • @JamesMilner are you sure that you're passing the right id parameter? Did you try running a SELECT statement with that id? I think that this value might not exist, that would explain the output you're receiving. – Kamil Gosciminski Oct 30 '15 at 22:09
1
0

Your code looks fine, double check what is $postid and if that matches a record with id in blog table.

Also make sure you are using correct database (check the connection details).

Side note: do not use echo var_dump(), var_dump() itself will echo it.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.