Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Sep 2012
    Location
    Philippines
    Posts
    11
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Exclamation [HELP]mysql_fetch_array() expects parameter 1 to be resource, boolean given in....

    Error:
    mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\panel.php on line 12

    Code:
    PHP Code:
    7. //Get Account Information
    8. $getuaccount mysql_query("SELECT * from members where username = '$uname'");
    9. $useraccount mysql_fetch_array($getuaccount);
    10. //Get Profile Information
    11. $getuprofile mysql_query("SELECT * from members-profile-info where username = '$uname'");
    12. $userprofile mysql_fetch_array($getuprofile);
    13.
    14. 
    echo 'Welcome ' $useraccount['username'] . '!';
    15. echo '<br/>Fullname:' $userprofile['fullname']; 
    Thanks in advance for those who will help

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You have no error handling in here.
    Your query has simply failed. The easiest way to determine why is to tack on an or die(mysql_error()); to the end of the mysql_query call. It will be a structural fault on it, not a data one (data/logic errors would produce empty resultsets, not false).

  • Users who have thanked Fou-Lu for this post:

    KazeFlame (12-28-2012)

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,216
    Thanks
    75
    Thanked 4,344 Times in 4,310 Posts
    Actually, the reason is obvious:
    Code:
    SELECT * from members-profile-info where username = '$uname'"
    MySQL will read that supposed table name as
    members MINUS profile MINUS info
    Just as PHP would. Just as JavaScript would. Etc.

    YOU CAN NOT USE A MINUS SIGN IN THE MIDDLE OF A NAME!

    Well, fortunately, with MySQL, you can.

    But if you do so, you *MUST* then tell MySQL that you are using a non-standard name by enclosing the entire name in back ticks (the ` character...shares a key with ~ normally).

    So:
    Code:
    $getuprofile = 
        mysql_query("SELECT * from `members-profile-info` where username = '$uname'")
        or die( mysql_error() );
    Incidentally, you don't show the rest of your PHP page, but almost surely you have goofed by making two separate queries in the code you showed us, insted of using a single query that JOINs the two tables.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    KazeFlame (12-28-2012)

  • #4
    New Coder
    Join Date
    Sep 2012
    Location
    Philippines
    Posts
    11
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Thanks
    I replaced
    PHP Code:
     $getuprofile mysql_query("SELECT * from members-profile-info where username = '$uname'"); 
    to
    PHP Code:
     $getuprofile mysql_query("SELECT * from members_profile_info where username = '$uname'"); 

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,216
    Thanks
    75
    Thanked 4,344 Times in 4,310 Posts
    But read what I said: There is a very very good chance that you should be making only *ONE* SQL query there, *NOT* two!!!

    Without seeing more of the page, I can't be sure, but I would give 3 to 1 odds, sight unseen.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,216
    Thanks
    75
    Thanked 4,344 Times in 4,310 Posts
    Just for example, try something like:
    Code:
    $sql = "SELECT m.userame, p.fullname 
            FROM members AS m, members_profile_info AS p
            WHERE m.username = p.username
            AND m.username = '$uname'";
    $getinfo = mysql_query( $sql ) or die( mysql_error );
    $userinfo = mysql_fetch_array($getinfo); 
    echo 'Welcome ' . $userinfo['username'] . '!'; 
    echo '<br/>Fullname:' . $userinfo['fullname'];
    ...
    If you need other fields from the two tables, LIST THEM EXPLICITLY in your SELECT statement. DO *NOT* USE select * if at all possible.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •