|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
I'm going nuts here. Ok this is what I'm trying to do. I have a page where someone picks from 2 different categories to sort data by. say the topic is food & they pick fruit & then subcategory apples. I'm sending this info to the results page as variables $selection & $type. now fruit would be one of my fields in my table & my code looks like this:
// Request the text $result = mysql_query("SELECT * FROM test WHERE @selection=@type"); if (!$result) { echo("<P>Error performing query: " . mysql_error() . "</P>"); exit(); } What am I doing wrong. Can I not use 2 variables like that in the select statement? I've tried many variations on this same basic idea. If anyone could please help me to fix this or has another suggestion to get these results I would be eternally grateful. I would be happy to clarify anything or provide any further info needed. sorry if this is stupid but I'm very new to both php & mysql. Last edited by tankdogg : September 11th, 2003 at 04:29 PM. |
|
#2
|
|||
|
|||
|
tankdogg,
Why are you using @ symbols instead of $ symbols for your variables? Also, depending on your version of PHP, you may need to reference your variables using the superglobal arrays: ie: $_POST['selection'] or $_GET['selection'] Hope that helps...
__________________
____________________________________________ Developer Shed Weekly Writer | DevArticles Forum Moderator Build Your Own KlipFolio Klip With PHP FrankManno.com - Under Construction Design Interactive Group - Under Construction |
|
#3
|
|||
|
|||
|
Why the @? Try it like this:
PHP Code:
The variable $type is between single quotes (I find it hard to see). |
|
#4
|
|||
|
|||
|
I've tried that also
can you use 2 variables like that? what happens is I get an error at the = |
|
#5
|
|||
|
|||
|
PHP Code:
Last edited by tankdogg : September 11th, 2003 at 07:10 PM. |
|
#6
|
|||
|
|||
|
Try this...
Store your query into a variable first... PHP Code:
That should display the exact query getting sent to the DB... Let me know what's displayed. |
|
#7
|
|||
|
|||
|
this is what I get
SQL Query: SELECT * FROM test WHERE ='' |
|
#8
|
||||
|
||||
|
Your variables aren't being set. Where are they coming from? Are they form results? If so, is register_globals turned on in your PHP config? Whether or not they are, it'd be a good idea to refer to variables within scope, so, for example, a form variable named "type" you would invoke as $_POST["type"] or $_GET["type"] depending on which method you used to submit the form.
Try setting values for the two variables above your statement and see what is echoed. If it works, then you've got a problem with how you're initially getting values into your variables. |
|
#9
|
|||
|
|||
|
thanks, setting the variables manually did work & gave me the correct results. What I was doing to test it was setting them via the url. in aplication they will be set via menu selections, which I now have set using links ie.
....<a href="results.php?selection=whatever&type=whatever"> any suggestions of a better way of doing this? because its not transferring the values over. |
|
#10
|
||||
|
||||
|
It's probably simply the case that register_globals is turned off. In your code, replace $selection and $type with $_GET[selection] and $_GET[type] and see how you fare with that. Also, you might want to consider wrapping each of those variables in addslashes() to help safeguard against an SQL injection attack (somebody hacking the URL and setting $type to "test; DROP TABLE users" for example). Your code would need to look like:
PHP Code:
|
|
#11
|
|||
|
|||
|
thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you
It now works perfectly. dhouston you are my new hero. thank you to everyone you are all great. and incase I forgot. THANK YOU. |
![]() |
| Viewing: Dev Articles Community Forums > Databases > General SQL Development > can anyone please help me??? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|