The variable $_POST automatically populated.
Try var_dump($_POST); to view the contents.
Access to individual values ββcan be obtained like this: echo $_POST["name"];
This, of course, assumes that your form uses the typical encoding of the form (ie enctype="multipart/form-data"
If your message data is in a different format (for example, JSON or XML, you can do something like this:
$post = file_get_contents('php://input');
and $post will contain raw data.
Assuming you are using the standard $_POST variable, you can check if the checkbox is checked:
if(isset($_POST['myCheckbox']) && $_POST['myCheckbox'] == 'Yes') { ... }
If you have a set of flags (e.g.
<form action="myscript.php" method="post"> <input type="checkbox" name="myCheckbox[]" value="A" />val1<br /> <input type="checkbox" name="myCheckbox[]" value="B" />val2<br /> <input type="checkbox" name="myCheckbox[]" value="C" />val3<br /> <input type="checkbox" name="myCheckbox[]" value="D" />val4<br /> <input type="checkbox" name="myCheckbox[]" value="E" />val5 <input type="submit" name="Submit" value="Submit" /> </form>
Using [ ] in the check box indicates that the selected script will be accessed by the PHP script as an array. In this case, $_POST['myCheckbox'] will not return a single row, but will return an array consisting of all the values ββof the checked flags.
For example, if I checked all the fields, $_POST['myCheckbox'] would be an array consisting of: {A, B, C, D, E} . Here is an example of how to get an array of values ββand display them:
$myboxes = $_POST['myCheckbox']; if(empty($myboxes)) { echo("You didn't select any boxes."); } else { $i = count($myboxes); echo("You selected $i box(es): "); for($j = 0; $j < $i; $j++) { echo($myboxes[$i] . " "); } }