Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-27-2012, 02:46 PM   PM User | #1
KazeFlame
New Coder

 
Join Date: Sep 2012
Location: Philippines
Posts: 11
Thanks: 9
Thanked 0 Times in 0 Posts
KazeFlame is an unknown quantity at this point
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
KazeFlame is offline   Reply With Quote
Old 12-27-2012, 02:57 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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).
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
KazeFlame (12-28-2012)
Old 12-27-2012, 07:43 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,162
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Actually, the reason is obvious:
Code:
SELECT * from members-profile-info where username = '$uname'"
MySQL will read that supposed table name as
Quote:
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.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
KazeFlame (12-28-2012)
Old 12-28-2012, 05:10 AM   PM User | #4
KazeFlame
New Coder

 
Join Date: Sep 2012
Location: Philippines
Posts: 11
Thanks: 9
Thanked 0 Times in 0 Posts
KazeFlame is an unknown quantity at this point
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'"); 
KazeFlame is offline   Reply With Quote
Old 12-28-2012, 05:38 AM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,162
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 12-28-2012, 05:43 AM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,162
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:16 PM.


Advertisement
Log in to turn off these ads.