Jump to content


Photo

forms and php


  • Please log in to reply
5 replies to this topic

#1 sarabjit

sarabjit
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 25 March 2006 - 05:33 AM

i'm at my wits end to solve this thing...

i have a simple form with only one field (userQuery) on one page which is being analyzed in the next...

here's the form:

<form action="search.php" method="get">
<tr><td colspan="2"><div align="center">
<input name="userQuery" type="text" id="userQuery" size="86">
</div></td></tr>
<tr><td width="225"><input type="submit" name="Submit" value="Search"></td>
</tr>
</form>


and here's the code in search.php which picks this query:

<?php
if (isset($userQuery)) {
...
}
else {
...
}
?>


the condition isset ($userQuery) however is always resulting in false, even though my address bar shows:
http://.../search.ph...t&Submit=Search

Any ideas??

#2 Hooker

Hooker
  • Members
  • PipPipPip
  • Advanced Member
  • 193 posts
  • LocationWales, UK

Posted 25 March 2006 - 06:02 AM

try:

if (isset($_GET['userQuery']))


#3 sarabjit

sarabjit
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 25 March 2006 - 06:07 AM

it worked!! thanks!!

will i need to do this for every variable??

#4 Hooker

Hooker
  • Members
  • PipPipPip
  • Advanced Member
  • 193 posts
  • LocationWales, UK

Posted 25 March 2006 - 06:11 AM

if your getting info from the URL it always helps :)

#5 sarabjit

sarabjit
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 25 March 2006 - 05:45 PM

Thanks!!

#6 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 25 March 2006 - 05:52 PM

[!--quoteo(post=358288:date=Mar 25 2006, 05:45 PM:name=sarabjit)--][div class=\'quotetop\']QUOTE(sarabjit @ Mar 25 2006, 05:45 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Thanks!!
[/quote]

just to elaborate on what Hooker said, ALWAYS ALWAYS ALWAYS use $_GET if refering to a URL parameter. and ALWAYS ALWAYS ALWAYS use $_POST if refering to variables posted by a form.
i've been done over with this in the past, as not paying attention to where you want the variables to come from can lead to all sorts of problems.
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users