#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Washington, DC
    Posts
    5
    Rep Power
    0
    For the life of me, I haven't been able to resolve a very annoying error which states:

    Warning: Supplied argument is not a valid MySQL result resource in filename.php on line 54

    The error occurs as a result of the following statements.

    $name_query = "select name from list_of_name where name_id = $SESSION[name_id]" or die("Error obtaining name");

    $name_result = mysql_query($name_query, $db);
    $name_data= mysql_fetch_array($name_result);

    PHP bombs on the mysql_fetch_array line. I've checked to make sure my session variable is loaded and the SQL will return exactly one row with one field value(I tried the same thing with mysql_result and got the same error.) Does anyone have any idea why this error is occuring?

    Thanks-in-advance
    Rodney

  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    10
    Rep Power
    0
    I've been getting the same exact error!

    Does anyone know what we're doing wrong?
  4. #3
  5. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Add this line after mysql_query():

    print mysql_error();

    You're trying to reference a result set that doesn't exist. The only reason that would happen is if there is an error in your query. mysql_error() will return the error mysql is generating so you can see what you did wrong.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    I am pretty sure MySQL doesn't like the brackets, try assigning $SESSION[name_id] to a different variable before running the query.
  8. #5
  9. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Excuse me, Freddie, but "HUH?"

    Mysql NEVER "sees" the brackets. Variables are replaced with their values by PHP before being sent to MySQL.

    the brackets are fine
  10. #6
  11. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,648
    Rep Power
    4493
    Don't you have to have braces arround and array value in a string, or isn't this needed anymore?

    $var = "This is my array {$array[0]}";

    Either way, the mysql_error will show us what's wrong.

    ---John Holmes...
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    77
    Rep Power
    15
    I have found sometimes i get this error if I haven't initiated the database connection. it might be a long shot but it could be the answer. i find that so often I forget to include my database connection file then i get this error and everytime i sit there for a while working out what it is. then i realise anyway, hope it helps.

    Dave
  14. #8
  15. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    John,

    Never needed braces for a one dimensional array. Multi-dimensional arrays will often cause problems in a quoted string which is why the braces solution was added in PHP4. I got too used to just using the . operator in those instances that I haven't used braces once.

    Either way, they're not needed here.

    Rod
  16. #9
  17. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    Perth West Australia
    Posts
    757
    Rep Power
    15
    $name_query =mysql_query("select name from list_of_name where name_id = '$SESSION[name_id]'"); optional .._id]',$db")

    if that does not work then as mentioned above either your connection is non existant or your table/field names are wrong - its very easy to mispell or get the case wrong for table/field names - yet not always so easy to spot them!

    ------------------
    Simon Wheeler
    FirePages -DHTML/PHP/MySQL

Similar Threads

  1. Highlight search result from mysql database search
    By Gurt in forum PHP Development
    Replies: 3
    Last Post: February 17th, 2004, 04:39 AM
  2. Custom error message for MySQL connection
    By dbr1066 in forum PHP Development
    Replies: 6
    Last Post: February 12th, 2004, 12:25 PM
  3. MySQL Error Access denied for user error
    By krishna_seshayy in forum MySQL Help
    Replies: 0
    Last Post: February 12th, 2004, 12:06 AM
  4. Mysql error
    By AIC in forum PHP Development
    Replies: 4
    Last Post: February 11th, 2004, 01:27 PM
  5. Replies: 1
    Last Post: January 30th, 2004, 12:46 PM

IMN logo majestic logo threadwatch logo seochat tools logo