-2

Why can't I store a boolean in an array? I get an error when I attempt to run it. (On line line 3)

The columns being retrieved with the exception of stamp are booleans. Here's a snippet of my code.

$BoolQ = "SELECT stamp, active, latvian, russianSpeaker FROM tasktable WHERE taskID=usrid;";
$Boolr = mysqli_query($connection,$BoolQ);
$Boolrow = mysqli_fetch_array($Boolr);

Error:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given
tahibuzij
  • 1
  • 1
  • 2
    The warning is telling you `$Rresponse` is false, nothing to do with storing booleans in array. – Jonnix Mar 12 '18 at 22:33
  • You can't store a boolean in a php array for the same reason you're not reading error message correctly. – N.B. Mar 12 '18 at 22:34
  • 1
    Where does $Rresponse even come from? – Jonnix Mar 12 '18 at 22:35
  • Sorry, mistake when renaming and putting it here. The problem still applies. – tahibuzij Mar 12 '18 at 22:42
  • And the reason is the same. Also it won't be the same error, it will be complaining you've passed it a string. – Jonnix Mar 12 '18 at 22:43
  • @JonStirling The Rrespose wasnt the problem, I just renamed the variable when copying it to stack. The error is the same – tahibuzij Mar 12 '18 at 22:51
  • 3
    Possible duplicate of [mysql\_fetch\_array()/mysql\_fetch\_assoc()/mysql\_fetch\_row()/mysql\_num\_rows etc... expects parameter 1 to be resource](https://stackoverflow.com/questions/2973202/mysql-fetch-array-mysql-fetch-assoc-mysql-fetch-row-mysql-num-rows-etc) – Jonnix Mar 12 '18 at 22:52
  • @JonStirling I'm using mysqli not mysql, I don't think it's a duplicate. – tahibuzij Mar 12 '18 at 23:05
  • @tahibuzij If you follow the link, you'll find it's not limited to mysql_* :) – Jonnix Mar 12 '18 at 23:07
  • It's simple. You're not checking whether your query succeeds. You're **assuming** it will. When it fails, like in your case, instead of a `resource`, you're feeding a `boolean` to `mysqli_fetch_array`. That's what the error tells you - it expected the parameter to be a resource of type `mysqli_result` but you gave it a `false`. Morale of the story: check whether queries succeed. This exact question shows up at least 50 times a day. – N.B. Mar 13 '18 at 14:09

1 Answers1

0

In the 3rd line of the code: $Boolrow = mysqli_fetch_array($BoolQ); , shouldn't you be using $Boolr as the parameter instead of $BoolQ? If that's a typo, which most probably it is, the result of mysqli_query is false, probably an issue with connection or the query.