Problem: mysql_fetch_array() expects parameter 1 to be resou

Codes here !

Moderators: macek, egami, gesf

krone
New php-forum User
New php-forum User
Posts: 2
Joined: Mon Apr 22, 2013 4:08 am

Problem: mysql_fetch_array() expects parameter 1 to be resou

Postby krone » Mon Apr 22, 2013 9:48 pm

$sql = "SELECT * FROM users WHERE id = " .$_SESSION['user_id'];
echo $sql;
$query = mysql_query($sql);
$result = mysql_fetch_array($query);
echo "</br>Username: ".$result['username']. '<br/>';


I can't figure it out what would be the problem here? Help please?

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Problem: mysql_fetch_array() expects parameter 1 to be r

Postby johnj » Tue Apr 23, 2013 6:00 am

Are you sure that your query is returning rows and not returning 'false' ??/

http://phillipnb.wordpress.com/2010/12/ ... -resource/

krone
New php-forum User
New php-forum User
Posts: 2
Joined: Mon Apr 22, 2013 4:08 am

Re: Problem: mysql_fetch_array() expects parameter 1 to be r

Postby krone » Tue Apr 23, 2013 9:58 pm

it started working somehow... tnx anyway

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Problem: mysql_fetch_array() expects parameter 1 to be r

Postby seandisanti » Thu Apr 25, 2013 8:10 am

You're probably going to have intermittent success with it, because you've not done the proper return validation. If there's an error executing your query, the return is going to be false, instead of a resource. so then when you go to fetch_array() you're going to run into the same error again.


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 2 guests