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
Linkjames
Forum Commoner
Posts: 90 Joined: Tue Sep 16, 2003 8:39 am
Post
by Linkjames » Tue Sep 16, 2003 8:39 am
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.
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Tue Sep 16, 2003 8:57 am
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 » Tue Sep 16, 2003 9:00 am
Thanks alot, that works great.
Cheers for your help - James
m3rajk
DevNet Resident
Posts: 1191 Joined: Mon Jun 02, 2003 3:37 pm
Post
by m3rajk » Tue Sep 16, 2003 3:37 pm
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