-4

I'm trying to do this:

<?php 
$query ="SELECT * FROM servers, bans WHERE servers.ServerID = bans.ServerID ORDER BY BanID DESC";
$result = mysql_query($query);
while($row=mysql_fetch_assoc($result)){     
?>

but I get this error:

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Access\repository\HT2\WH\www.voltzgaming.com\public_html\GBans\index.php on line 139
Jonah Hart
  • 35
  • 5
  • Print `mysql_error()` to see the error in your SQL. – Barmar Jan 07 '14 at 22:20
  • 2
    If you put your error message into the search box, how many questions do you see with the exact same error? – Barmar Jan 07 '14 at 22:21
  • Are you _connected_ to your database? You need to do error checking, _always_ with the `mysql_*()` extension. – Michael Berkowski Jan 07 '14 at 22:21
  • 1
    meanwhile, no new code should be written with `mysql_*()`. The extension has been deprecated, and new code should be built with either the MySQLi or PDO extensions. – Michael Berkowski Jan 07 '14 at 22:22
  • 1
    Bored with this. Why does nobody check for error with their MySQL code? –  Jan 07 '14 at 22:23
  • @MikeW I'm more puzzled by the fact that apparent newbies are still using the MySQL extension. Where are they getting this advice? – Phil Jan 07 '14 at 22:25
  • 1
    @MikeW [because of garbage like this](http://www.w3schools.com/php/func_mysql_fetch_array.asp) all over the interwebs. – Michael Berkowski Jan 07 '14 at 22:25
  • @Phil Any of hundreds of out-of-date tutorials on the web, I'd guess. –  Jan 07 '14 at 22:26

1 Answers1

1

Your mysql_query($query) is returning a false because you have a syntax error in the SQL.

Use mysql_error() after the query is run to see what the problem is.

castis
  • 8,154
  • 4
  • 41
  • 63