/    Sign up×
Community /Pin to ProfileBookmark

How to work check box? Help,simple question

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:

[code=php]
<?php

if (isset($_POST[‘guest’]))
{
if (!empty ($guest))
{include(“logout.php”);}
else
{header(‘Location: home.php’);}
}
?>
[/code]

and FORM HTML:

[code=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>
[/code]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@LimpBagelOct 03.2005 — use the isset() function. If the checkbox is not checked, you won't see it in POST at all.

Kinda like you are doing:

[code=php]
if(isset($_POST['guest'])) {
$guest = 1;
} else {
$guest = 0;
}[/code]
Copy linkTweet thisAlerts:
@toplisekauthorOct 03.2005 — If it is not checked but pressed SUBMIT I would like to have value 0 for $guest

Is this possible?
Copy linkTweet thisAlerts:
@LimpBagelOct 03.2005 — I believe the code I gave will do that.
Copy linkTweet thisAlerts:
@toplisekauthorOct 03.2005 — 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. ?
×

Success!

Help @toplisek spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...