Quick problem

SpaceshipSpaceship
SpaceshipSpaceship
SpaceshipSpaceship
Watch

SiKing

Registered MemberEstablished Member
Impact
6
Hey, Can anybody tell me what's wrong with the following? I'd be very grateful

PHP:
$query = mysql_query("SELECT * FROM FORUM_users WHERE username='$sessionusername'");
$sql = mysql_query($query) or die(mysql_error());
    $obj = mysql_fetch_object($sql);
    $postcount = $obj->user_posts; 

echo "$postcount";
Returns

PHP:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #5' at line 1
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
I think it's because $sessionusername contains 'Resource id #5' and # should be escaped. Anyway I'm not sure it's normal you have $sessionusernam set to that... Try to display the value before execute the query...
 
0
Close
Thanks for the reply. I have retyped te code in the following way where $username is the username for the session:

PHP:
$query = mysql_query("SELECT * FROM FORUM_users WHERE username='$username'");
$result=mysql_query($query);
$num=mysql_num_rows($result);

$i=0;
while ($i < $num) {

$posts=mysql_result($result,$i,"user_posts");

$i++;
}

echo "$posts";


This returns

PHP:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /usr/local/psa/home/vhosts/darkfx.co.uk/httpdocs/studios/test.php on line 13
 
Last edited:
0
Close
I think the problem is that you are trying to execute the query twice.

PHP:
 $query = mysql_query("SELECT * FROM FORUM_users WHERE username='$username'");

The above line actually takes the sql statement, executes it, and assigns the result to $query. In the next line:

PHP:
$result=mysql_query($query);

You try to do a query again, but this time, you are using the variable $query, which is already a result set from the previous line.

I think the solution might be obvious now. This should work:

PHP:
$query = "SELECT * FROM FORUM_users WHERE username='$username'";

$result=mysql_query($query);

Happy coding.

-Bob
 
1
Close
This man, he is a legend. I thank you so much
 
0
Close
miseria said:
This man, he is a legend. I thank you so much

HAHA! :bingo:
 
0
Close
CatchedCatched

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back