CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   MySQL (http://www.codingforums.com/forumdisplay.php?f=7)
-   -   [HELP]mysql_fetch_array() expects parameter 1 to be resource, boolean given in.... (http://www.codingforums.com/showthread.php?t=284900)

KazeFlame 12-27-2012 02:46 PM

[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 :)

Fou-Lu 12-27-2012 02:57 PM

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).

Old Pedant 12-27-2012 07:43 PM

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.

KazeFlame 12-28-2012 05:10 AM

Thanks :D
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'"); 


Old Pedant 12-28-2012 05:38 AM

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.

Old Pedant 12-28-2012 05:43 AM

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.


All times are GMT +1. The time now is 10:04 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.