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) }
7
  • Post an example of what the echo var_dump($stmt); will return. Commented Oct 30, 2015 at 22:03
  • Hi Racil, I've edited the post to clarify. Commented Oct 30, 2015 at 22:05
  • OK, what is the value of $postid? And can you confirm that this value exists in the database? Commented Oct 30, 2015 at 22:08
  • / Check whether the execute() succeeded is that a typo? Commented Oct 30, 2015 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. Commented Oct 30, 2015 at 22:09

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.