Blekk Posted December 5, 2006 Share Posted December 5, 2006 Hi,On my form I have a checkbox, all I want to do is return 1 if the box is checked and 0 if it isn't, I have looked for tutorials but they are all very complex or not to the point.I know I need this much:[code]<?php $result = $_POST['checkbox']; ?>[/code]Or don't I? Is it something different?Can anyone help?Thanks,Any reply is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/29541-how-to-use-a-checkbox-with-php/ Share on other sites More sharing options...
Blekk Posted December 5, 2006 Author Share Posted December 5, 2006 I have done it now, so this topic can be deleted, but for anyone else who wants to know:[code]if(isset($_POST['checkbox'])){ print "Checkbox = 1";}[/code]Thanks anyway :P Quote Link to comment https://forums.phpfreaks.com/topic/29541-how-to-use-a-checkbox-with-php/#findComment-135548 Share on other sites More sharing options...
papaface Posted December 5, 2006 Share Posted December 5, 2006 [code]if ($_POST['checkbox'] = "Y") { echo "1"; }else { echo "0"; }[/code] Quote Link to comment https://forums.phpfreaks.com/topic/29541-how-to-use-a-checkbox-with-php/#findComment-135550 Share on other sites More sharing options...
.josh Posted December 5, 2006 Share Posted December 5, 2006 [code]<?php echo ($_POST['myCheckbox'] ? "your box was checked." : "your box was not checked."; echo <<<FORM <form action = '{$_SERVER['PHP_SELF']}' method = 'post'> <input type = 'checkbox' name = 'myCheckbox' value = 'somevalue'> blah <br/> <input type = 'submit' value = 'submit'> </form>FORM;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/29541-how-to-use-a-checkbox-with-php/#findComment-135551 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.