Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Problem: mysql_fetch_array() expects parameter 1 to be resou

Codes here !

Moderators: macek, egami, gesf

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?
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 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/
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 krone » Tue Apr 23, 2013 9:58 pm

it started working somehow... tnx anyway
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 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.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron