-1

a really frustrating one for me today .. Keep getting

mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given

HOWEVER , there is data in the table I am querying. I have even tried doing a basic SELECT * to see if it will display ANYTHING at all from the table but it simply gives me the above error.

my very simple query is

$test = mysqli_query($con, "SELECT * FROM `workshop-items` WHERE `wsiid` = '1'");
$testr = mysqli_fetch_assoc($test);
echo $testr['code'];

In the table there are 7 columns each with a value however no matter what it just gives me this flipping error.

Please help guys I'm really pulling hair out now.

The $con values are correct because I use it for the login and other queries.

Aung Myo Linn
  • 2,724
  • 3
  • 26
  • 37
Chris Yates
  • 63
  • 10
  • Did you run this query in sql ? – Saad Suri Jun 15 '17 at 08:30
  • try it with the database name in it: `databaseName`.`workshop-items` – verhie Jun 15 '17 at 08:31
  • nope still didnt work .. really puzzling me now – Chris Yates Jun 15 '17 at 08:41
  • 2
    The value returned by [`mysqli_query()`](http://php.net/manual/en/mysqli.query.php) is `FALSE` not because there is no data in the table, as it seems you think, but because its second argument is not a valid SQL query. Use the value returned by [`mysqli_error($con)`](http://php.net/manual/en/mysqli.error.php) to find out what is wrong with it (most probably a misspelled column or table name). – axiac Jun 15 '17 at 08:45
  • @axiac I just ran SELECT * FROM `workshop-items` WHERE `itemgroup` = 'Service' in HeidiSQL and it returned correct data As soon as the query is on the page it does nothing but throw an error so i know column names etc are correct i have ` around itemgroup and Service but when I pasted code here it got removed – Chris Yates Jun 15 '17 at 08:54
  • What's the error returned by `mysqli_error()`? – axiac Jun 15 '17 at 08:58
  • Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given That is the only error being displayed – Chris Yates Jun 15 '17 at 09:02
  • Try removing quotes from your SQL query for column/table names – Deepansh Singh Jun 15 '17 at 09:12
  • tried that too exact same... thats why im really stumped – Chris Yates Jun 15 '17 at 09:23

1 Answers1

-1

try this

$test = mysqli_query($con, "SELECT * FROM `workshop-items` WHERE `wsiid` = '1'") or die(mysqli_error($con));
Riaz Laskar
  • 1,313
  • 9
  • 17
  • 1
    **Never** use `or die()`. Implement proper error handling. Display a message, let the user know something happened. Don't just throw a white screen in their face. – axiac Jun 15 '17 at 08:40
  • 1
    @axiac i put the die just to see whats wrong with his script for debug. – Riaz Laskar Jun 15 '17 at 08:45