using checkboxes

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
jmn123
Forum Newbie
Posts: 2
Joined: Tue Jun 24, 2003 7:14 am

using checkboxes

Post by jmn123 »

I've been working my way through the PHP Beginners Tutorial (http://www.phpcomplete.com/tutorials/?i ... adtutorial) - I'm following the logic and even able to do some problem solving when stuff isn't working but I've come up against one I have no idea how to clear up. I've got to "checkboxes" - I've set up an HTML form with two checkboxes and a submit and then set up a checkboxTest.php - code:
<?php
if($Checkbox1)
{
echo("The first checkbox was checked<br>\n");
}
if($Checkbox2)
{
echo("The second checkbox was checked<br>\n");
}
?>
With the code this way - nothing happens.
The obvious candidate to change is the "if"
if $_POST['Checkbox1']
However that returns an error message about expecting '(' in line 2 so I have no idea what else to try.
Please help.
thanks
Judith
There's also a second
User avatar
releasedj
Forum Contributor
Posts: 105
Joined: Tue Jun 17, 2003 6:35 am

Post by releasedj »

This should work providing your using the POST method, otherwise replace _POST with _GET.

Code: Select all

if ($_POST['Checkbox1'])
jmn123
Forum Newbie
Posts: 2
Joined: Tue Jun 24, 2003 7:14 am

Post by jmn123 »

thanks for the reply - I'd actually figured out that I needed the () brackets about three hours after I'd posted the message.
JMN
Gleeb
Forum Commoner
Posts: 87
Joined: Tue May 13, 2003 7:01 am
Location: UK
Contact:

Post by Gleeb »

It might be worth noting that in recent releases of PHP, it has become default to NOT auto-populate variable with GET/POST/COOKIE infos. this is a 'good thing' in my book, as it makes thing that little bit more secure. (No cookie spoofing)

Try using the superglobals $_GET[], $_POST[] and $_COOKIE[] instead.
Post Reply