0

What should be a simple mySQL call from PHP is generating the mySQL error mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given

Here's the code:

$updateSQL = "UPDATE content SET type='type1', updated_by='Fred', date_updated = NOW() WHERE id=123";

$mysqli = mysqli_connect($hostname, $username,password, $database);

$update = mysqli_query($mysqli, $updateSQL) or die(mysqli_error($mysqli));
$row_update = mysqli_fetch_assoc($update);
$totalRows_update = mysqli_affected_rows($mysqli);

At first I thought the problem was the or die(mysqli_error($mysqli)), but I get the same error even if I comment that part out. When I check $update with gettype($update), it does show a type of boolean, but I don't understand why.

BTW, the update query itself seems to execute with no problems.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
jalperin
  • 2,664
  • 9
  • 30
  • 32
  • can you show whats inside $updateSQL – Poorya Mohammadi Dec 26 '13 at 22:27
  • 2
    Typically it's an error in your SQL statement, which you don't show – Mark Baker Dec 26 '13 at 22:28
  • 5
    if you are doing an update...you dont have nothing to fetch, I think – Emilio Gort Dec 26 '13 at 22:29
  • http://www.php.net/manual/en/mysqli.error.php – zerkms Dec 26 '13 at 22:29
  • 2
    I think zerkms is correct. Since it's an update query, there's no result set, so the fetch_assoc doesn't make any sense and probably is generating the error. The actual query isn't missing the semicolon. – jalperin Dec 26 '13 at 22:37
  • Ok. I edited your question and added the missing semi-colon. In the future, please post actual production code, and everything relevant to the problem. It'll leave all the guesswork out of things. ;-) – Funk Forty Niner Dec 26 '13 at 22:38
  • 1
    Please try comment `$row_update = mysqli_fetch_assoc($update)` and you wont get more errors – Emilio Gort Dec 26 '13 at 22:39
  • It is being evaluated as `boolean` because you did not bother [reading the documentation](http://www.php.net/manual/en/mysqli.query.php#refsect1-mysqli.query-returnvalues). – Sverri M. Olsen Dec 26 '13 at 22:55
  • possible duplicate of [mysql\_fetch\_array() expects parameter 1 to be resource, boolean given in select](http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-in-select) – John Conde Jan 02 '14 at 00:29

1 Answers1

1

Since you are not returning a recordset in you query you don't have to fetch any result, My advice is remove $row_update = mysqli_fetch_assoc($update); line

Emilio Gort
  • 3,475
  • 3
  • 29
  • 44