4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 Using text in where clause
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
Kdawg
Senior WebHelper
Senior WebHelper


Joined: 21 Apr 2003
Posts: 153

PostPosted: Sun Feb 08, 2004 5:11 pm (13 years, 8 months ago) Reply with QuoteBack to Top

How can I use text in the where clause in php, like
Code:
SELECT state FROM people WHERE name = $name

and $name would be joe?
I allways get this error when I do this
Code:
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/stingbas/public_html/webtech/pagecreator/disp.php on line 6

I think it means it didnt find anything but I dont know how to get it to work.
OfflineView User's ProfileFind all posts by KdawgSend Personal Message
adam
Forum Moderator & Developer



Joined: 26 Jul 2002
Posts: 704
Location: UK

PostPosted: Sun Feb 08, 2004 7:30 pm (13 years, 8 months ago) Reply with QuoteBack to Top

after the call to mysql_query(), add:
Code:
print mysql_error();

so you can see why the query failed...if it simply hadn't found anything, it wouldn't produce that error.

________________________________
It's turtles all the way down...
OfflineView User's ProfileFind all posts by adamSend Personal MessageVisit Poster's Website
OllieMaitland
Junior WebHelper
Junior WebHelper


Joined: 06 Dec 2003
Posts: 25

PostPosted: Mon Feb 09, 2004 12:17 am (13 years, 8 months ago) Reply with QuoteBack to Top

Have you tried running the query through phpmyadmin? I normally do this to test queries then when you put it in the code it works straight off...

Also on another note you should really have unenclosed query strings because if you have spaces or ' in the string the query will fail...

so it probably should be:

Code:

SELECT state FROM people WHERE name = ' ".$name." '


..also if $name is a variable from a form you should use:

Code:

SELECT state FROM people WHERE name = ' ".$_POST['name']." '


other things to watch out for is whether the field names are the same case as in the table.

hope you get it working Wink
OfflineView User's ProfileFind all posts by OllieMaitlandSend Personal MessageSend email
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   




You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot edit your posts in this forum.
You cannot delete your posts in this forum.
You cannot vote in polls in this forum.


Page generation time: 0.04698 seconds :: 17 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme