0

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

It says my syntax has errors, I cant seem to find the error.

$query_admin = "SELECT * FROM `user_accounts` WHERE `id` =1 AND `name` LIKE {$login_user_name}AND `password` LIKE {$login_password }";

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
        echo $query_result;
    }

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Database Manager\admin\sql_functions.php on line 32
Community
  • 1
  • 1
NSanjay
  • 223
  • 1
  • 6
  • 13
  • You are missing a space here: `{$login_user_name}AND` Please always output the final generated queries with the actual values inserted - they make most errors very obvious. Also use `echo mysql_error()` to see the SQL error – Pekka Mar 06 '11 at 09:19
  • are you executing the query using the mysql_query() function ? – Muhamad Bhaa Asfour Mar 06 '11 at 09:28
  • Yes I am executing the query using the mysql_query() function. – NSanjay Mar 06 '11 at 09:37

1 Answers1

1

@Pekka is right that there is an error in your query: you need a space there.

Also, you use $result in your mysql_fetch_array(), but that is never actually set. It can be you omitted it, and it is just false because of the query error ofcourse, but otherwise that's a second bug :)

Your code example is a bit incomplete. In the comments you do mention you are actually doing the query using mysql_query(). But it is not shown in the code.

In what var do you save the result? Are you saving it in $result (as you use that for the mysql_fetch_array) and if so, what is $query_result in your while?

Try this:

$query_admin = "SELECT * FROM `user_accounts` WHERE `id` =1 AND `name` LIKE {$login_user_name} AND `password` LIKE {$login_password }";

$result = mysql_query($query_admin);

if (!$result) {
    die('Invalid query: ' . mysql_error());
}

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
    var_dump($row);
}

and work from there.

Nanne
  • 63,347
  • 16
  • 116
  • 159