[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 09-12-2005, 09:37 AM   #1 (permalink)
SQLdumpster.com
 
miseria's Avatar
 
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 545
205.50 NP$ (Donate)

miseria will become famous soon enoughmiseria will become famous soon enough


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'");
$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 syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #5' at line 1
miseria is offline  
Old 09-12-2005, 09:55 AM   #2 (permalink)
Senior Member
 
dgaussin's Avatar
 
Join Date: May 2004
Location: France
Posts: 1,294
85.60 NP$ (Donate)

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 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, 10:08 AM   #3 (permalink)
SQLdumpster.com
 
miseria's Avatar
 
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 545
205.50 NP$ (Donate)

miseria will become famous soon enoughmiseria will become famous soon enough


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'");
$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 Code:
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 by miseria; 09-12-2005 at 10:12 AM.
miseria is offline  
Old 09-12-2005, 10:51 AM   #4 (permalink)
NamePros Regular
 
moondog's Avatar
 
Join Date: Jun 2004
Posts: 476
3,677.00 NP$ (Donate)

moondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of light


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);
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
__________________
The mass purge has begun.
moondog is offline  
Old 09-12-2005, 11:46 AM   #5 (permalink)
SQLdumpster.com
 
miseria's Avatar
 
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 545
205.50 NP$ (Donate)

miseria will become famous soon enoughmiseria will become famous soon enough


This man, he is a legend. I thank you so much
miseria is offline  
Old 09-12-2005, 01:56 PM   #6 (permalink)
NamePros Regular
 
moondog's Avatar
 
Join Date: Jun 2004
Posts: 476
3,677.00 NP$ (Donate)

moondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of light


Quote:
Originally Posted by miseria
This man, he is a legend. I thank you so much
HAHA!
__________________
The mass purge has begun.
moondog is offline  
Closed Thread


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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

Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 11:19 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85