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
wilko18
Forum Newbie
Posts: 4 Joined: Fri Apr 21, 2006 6:37 am
Post
by wilko18 » Sun Apr 23, 2006 2:24 pm
Anyone know why this really basic IF loop doesn't work?
I just need the code to chenge the value of the variable IF the box is ticked...which it is by default, however the values output is "Not Working" and not "it works".
Code: Select all
<input name="tick1" type="checkbox" id="tick1" value="checkbox" checked="checked" />
<?php
$price = "not working";
if (isset($_POST['tick1']))
{
$price = "it works";
}
echo $price;
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Apr 23, 2006 2:45 pm
Is the form the checkbox apart of use the post method?
wilko18
Forum Newbie
Posts: 4 Joined: Fri Apr 21, 2006 6:37 am
Post
by wilko18 » Sun Apr 23, 2006 2:56 pm
I don't quite understand what you mean?
The code I posted is the whole code...we're just trying to get the
if (isset($_POST['tick1']))
to return true...which currently it never does.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Apr 23, 2006 3:02 pm
You have to have a form to submit via post (ignoring Ajax.)
R4000
Forum Contributor
Posts: 168 Joined: Wed Mar 08, 2006 12:50 pm
Location: Cambridge, United Kingdom
Post
by R4000 » Sun Apr 23, 2006 3:04 pm
page1.php:
Code: Select all
<form action="page2.php" method="POST">
<input name="tick1" type="checkbox" id="tick1" value="checkbox" checked="checked" />
<input name="submit" type="submit" value="Test!" />
</form>
page2.php:
Code: Select all
<?php
$price = "not working";
if ($_POST['tick1']) {
$price = "it works";
}
echo $price;
?>
psychotomus
Forum Contributor
Posts: 487 Joined: Fri Jul 11, 2003 1:59 am
Post
by psychotomus » Sun Apr 23, 2006 4:11 pm
shouldn't
<input name="tick1" type="checkbox" id="tick1" value="checkbox" checked="checked" /
be checked='true"?
im not an html master. thats why i use an html editor.
R4000
Forum Contributor
Posts: 168 Joined: Wed Mar 08, 2006 12:50 pm
Location: Cambridge, United Kingdom
Post
by R4000 » Sun Apr 23, 2006 4:13 pm
i dont think it should be either
I'm pretty sure it should be:
Code: Select all
<input type="checkbox" name="NAME" checked />
My bad for not noticing (correct me if im wrong... but im damn sure this is right)
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Apr 23, 2006 4:14 pm
What it should be depends on what (X)HTML standard you are following. In HTML 4, just "checked," but in XHTML, 'checked="checked".'