NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Quick problem

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 09-12-2005, 10:37 AM THREAD STARTER               #1 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 573
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




Quick problem


Hey, Can anybody tell me what's wrong with the following? I'd be very grateful

PHP Code:
$query mysql_query("SELECT * FROM FORUM_users WHERE username='$sessionusername'");
????: NamePros.com http://www.namepros.com/programming/123073-quick-problem.html
$sql mysql_query($query) or die(mysql_error());
    
$obj mysql_fetch_object($sql);
    
$postcount $obj->user_posts

echo 
"$postcount"
Returns

PHP Code:
You have an error in your SQL syntaxcheck the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #5' at line 1 
Encenta.com is offline  
Old 09-12-2005, 10:55 AM   #2 (permalink)
Senior Member
 
dgaussin's Avatar
Join Date: May 2004
Location: France
Posts: 1,226
dgaussin is a splendid one to beholddgaussin is a splendid one to beholddgaussin is a splendid one to beholddgaussin is a splendid one to beholddgaussin is a splendid one to beholddgaussin is a splendid one to beholddgaussin is a splendid one to beholddgaussin is a splendid one to behold
 




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...
dgaussin is offline  
Old 09-12-2005, 11:08 AM THREAD STARTER               #3 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 573
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




Thanks for the reply. I have retyped te code in the following way where $username is the username for the session:

PHP Code:
$query mysql_query("SELECT * FROM FORUM_users WHERE username='$username'");
????: NamePros.com http://www.namepros.com/showthread.php?t=123073
$result=mysql_query($query);
????: NamePros.com http://www.namepros.com/showthread.php?t=123073
$num=mysql_num_rows($result);

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

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

$i++;
}

echo 
"$posts"

This returns

PHP Code:
Warningmysql_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 by Encenta.com; 09-12-2005 at 11:12 AM.
Encenta.com is offline  
Old 09-12-2005, 11:51 AM   #4 (permalink)
NamePros Regular
 
moondog's Avatar
Join Date: Jun 2004
Posts: 587
moondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to all
 



I think the problem is that you are trying to execute the query twice.

PHP Code:
 $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 Code:
$result=mysql_query($query); 
????: NamePros.com http://www.namepros.com/showthread.php?t=123073
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 Code:

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

$result=mysql_query($query); 
Happy coding.

-Bob
__________________
Can't wait to be out of this forsaken business. Getting close! :)
moondog is offline  
Old 09-12-2005, 12:46 PM THREAD STARTER               #5 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 573
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




This man, he is a legend. I thank you so much
Encenta.com is offline  
Old 09-12-2005, 02:56 PM   #6 (permalink)
NamePros Regular
 
moondog's Avatar
Join Date: Jun 2004
Posts: 587
moondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to allmoondog is a name known to all
 



Originally Posted by miseria
This man, he is a legend. I thank you so much
HAHA!
__________________
Can't wait to be out of this forsaken business. Getting close! :)
moondog is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Very wierd Windows problem Ravi_s Web Design Discussion 0 08-12-2005 11:29 PM
Problem at godaddy or others not as quick??? quality Domain Name Discussion 3 08-04-2005 08:52 PM
MySQL or PHP problem Wildchild22 Website Development 10 07-14-2005 06:24 AM
vBulletin Problem!!!!!!!!!!!! domaino Programming 11 06-23-2005 07:29 AM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 09:21 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger