Jump to content

How to use a checkbox with php


Blekk

Recommended Posts

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.
Link to comment
https://forums.phpfreaks.com/topic/29541-how-to-use-a-checkbox-with-php/
Share on other sites

[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]
     

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.