My form code isn't behaving as expected

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Linkjames
Forum Commoner
Posts: 90
Joined: Tue Sep 16, 2003 8:39 am

My form code isn't behaving as expected

Post by Linkjames »

Bad code ;)

Ok, the below code is supposed to either present the form, or if the form has been filled, just say "hello", but when I hit submit, it brings the form back up. Any ideas?

Code: Select all

<?php 
if ($c != 1)
{
?>
<form name="form1" action="search.php?=c">
  <input name="search" type="text" id="search" value="Enter search here" size="50">
  <input type="submit" value="Search!">
</form>
<?php
} else if ($c==1) {
echo ("hello");
};
?>
Cheers for any help guys.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

you arem't setting the value of $c to anything when you submit your form.

Try this

Code: Select all

<?php 
if ($_GET['c'] != 1) 
{ 
?> 
<form name="form1" action="search.php" method="GET">
   <input type="hidden" name="c" value="1">
  <input name="search" type="text" id="search" value="Enter search here" size="50"> 
  <input type="submit" value="Search!"> 
</form> 
<?php 
} else if ($_GET['c']==1) { 
echo ("hello"); 
}; 
?>
Linkjames
Forum Commoner
Posts: 90
Joined: Tue Sep 16, 2003 8:39 am

Post by Linkjames »

Thanks alot, that works great.

Cheers for your help - James
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Re: My form code isn't behaving as expected

Post by m3rajk »

althought your problem was solved, you should note that this is wrong:

<form name="form1" action="search.php?=c">



that sets an emtpy variable to c.


& is the seperator between parts of the get /post strings
Post Reply