0

I have a mySQL query:

mysql_query("SELECT username_usr FROM user_usr WHERE username_usr=$name")

which I store in the variable $username_check. Then I store mysql_fetch_array($username_check) in a variable.

When I run the script I get an error that mysql_fetch_array expects a resource, boolean given;

I must be making some simple mistake but by FSM i cannot find it.

Paul
  • 135,475
  • 25
  • 268
  • 257
Xitcod13
  • 5,801
  • 7
  • 37
  • 80

1 Answers1

1

Your query has a syntax error, and you're getting back a boolean FALSE:

mysql_query("SELECT username_usr FROM user_usr WHERE username_usr='$name'")
                                                                  ^-----^--- missing

Never assume a query succeeds. ALWAYS check the return value for failurE:

$result = mysql_query(...) or die(mysql_error());

is the bare mininum you should always have in place.

Marc B
  • 348,685
  • 41
  • 398
  • 480
  • yes but i think it would still work the problem i had is an additional " in front of the value of $name because i used explode() to get name from somewhere else. – Xitcod13 Jun 17 '12 at 03:08
  • It would not have worked in this case but in other cases variables from $_GET[] are returned with qoutes. Thanks for your help i was really having problems with this – Xitcod13 Jun 17 '12 at 03:23