Click to See Complete Forum and Search --> : How to work check box? Help,simple question


toplisek
10-03-2005, 07:30 AM
I would like to perform IF script if there is SUBMIT. Do you know how to give variable $guest value 0 if it is not checked? Need help
Code is the following:

<?php

if (isset($_POST['guest']))
{
if (!empty ($guest))
{include("logout.php");}
else
{header('Location: home.php');}
}
?>

and FORM HTML:

<FORM>
<form method="post" >
<input type="checkbox" name="guest" value="1" checked="checked">I would like to be user as Guest
<br /><center><input type="image" src="images/submit.gif" /></center>
</FORM>

LimpBagel
10-03-2005, 08:13 AM
use the isset() function. If the checkbox is not checked, you won't see it in POST at all.

Kinda like you are doing:


if(isset($_POST['guest'])) {
$guest = 1;
} else {
$guest = 0;
}

toplisek
10-03-2005, 08:16 AM
If it is not checked but pressed SUBMIT I would like to have value 0 for $guest
Is this possible?

LimpBagel
10-03-2005, 08:25 AM
I believe the code I gave will do that.

toplisek
10-03-2005, 10:59 AM
It I put

if ($guest==1) {echo 'You are user as Guest.'; echo 'Please click here to proceed.';}
if ($guest==0)
{echo 'Please click <a href="membership.php">here</a> to log in'; }
there will be all message Please click here on the start. Do you have suggestion how to avoid message at the start. When I do not check the box it will be the same message.
It works when it is checked but variable $guest is 0 at the start. :)