Page 1 of 1

using checkboxes

Posted: Tue Jun 24, 2003 7:14 am
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

Posted: Tue Jun 24, 2003 7:17 am
by releasedj
This should work providing your using the POST method, otherwise replace _POST with _GET.

Code: Select all

if ($_POST['Checkbox1'])

Posted: Tue Jun 24, 2003 10:19 pm
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

Posted: Wed Jun 25, 2003 8:18 am
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.