-1

In my code I am trying to query a database table with the following:

$queryLogItemsStatement = "SELECT FROM transactions WHERE user1ID='". $userID . "' ORDER BY date DESC";
$queryLogItems = mysql_query($queryLogItemsStatement, $connection); 
while ($rowLog = mysql_fetch_array($queryLogItems)){ //line 33
}

but when I run it I get the error:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Users/iddogino/Sites/serverFilesPayaway/user/logForUser.php on line 33

Now I know that the database connection works because I have used it successfully in the past...

What may the problem be?

Ian Atkin
  • 6,106
  • 2
  • 15
  • 23
Iddo Gino
  • 230
  • 2
  • 11
  • 1
    Chances are that `mysql_query` is returning false. It does this on error. Check `mysql_error()`? **Heads up:** they're *removing* the mysql_ family of functions in a future version of PHP. Now would be a *great* time to [switch to PDO](http://php.net/book.pdo) or [mysqli](http://php.net/book.mysqli). – Charles Dec 08 '12 at 10:11
  • 1
    your select failed, debug that- your not actully selecting anything, did you for forget the * or column names –  Dec 08 '12 at 10:11
  • What are you selecting exactly ?! i think you should mention the fields to be selected in your query. – Mehdi Karamosly Dec 08 '12 at 10:15
  • It was a problem with the actual statement. Why is the mysql_ family of functions being removed? – Iddo Gino Dec 08 '12 at 10:17
  • @Iddo, it's an antiquated way to access MySQL that was poorly designed and implemented. It's been *obsolete* since PHP 5.0, released back in *2004*. It will be formally deprecated in the next major release of PHP ("5.5"?), and may be removed during any future major release afterward. It should not be used in new code. If you're still learning PHP, try and take the time to *un*-learn the `mysql_` family of functions in favor of PDO or mysqli. – Charles Dec 08 '12 at 10:23

1 Answers1

3

You are not selecting any columns

SELECT FROM transactions
      ^----------------------missing here

You probably wanted

SELECT * FROM transactions

to select all columns. Or you can name the columns you want to select like this

SELECT column_name1, column_name2, column_name3 FROM transactions
juergen d
  • 195,137
  • 36
  • 275
  • 343