php - Checkbox in html -
i have these group of checkboxes
upon submit .. want echo chosen checkboxes in page (pay.php)
for example: if chose park , wash .. in pay.php page want echo park , wash wash (the last chosen checkbox) how make chosen checkboxes printed??
<form name="input" action="pay.php" method="post"> services: <br/> <input type="checkbox" name="service" value="park" checked>park <br/> <input type="checkbox" name="service" value="wash">wash <br/> <input type="checkbox" name="service" value="check tires">check tires <br/> <input type="checkbox" name="service" value="fill oil">fill oil <br/> <input type="checkbox" name="service" value="check brakes">check brakes <br/> <input type="submit" value="go paying" /> </form>
in pay.php:
<?php //$servicetext=$_post["service"]; // echo $servicetext; ////the array part//// echo "<table border='0'> <tr> <th> //print array here </th> <th> </th> <th> </th> <th> </th> <th> </th> <tr/>"; ?>
since check boxes multiple need create array of name same name of input type.
<form name="input" action="pay.php" method="post"> services: <br/> <input type="checkbox" name="service[]" value="park" checked>park <br/> <input type="checkbox" name="service[]" value="wash">wash <br/> <input type="checkbox" name="service[]" value="check tires">check tires <br/> <input type="checkbox" name="service[]" value="fill oil">fill oil <br/> <input type="checkbox" name="service[]" value="check brakes">check brakes <br/> <input type="submit" value="go paying" /> </form>
in pay.php, can access each check box value in below formats
<?php if(!empty($_post['service'])) { foreach($_post['service'] $service) { echo $service; //rest of code } }
edited
in pay.php
<?php if(!empty($_post['service'])) { $i = 0; $selarr = array(); //i took array store these check box values foreach($_post['service'] $service) { $selarr[$i] = $service; $i++; } }
edited2
<?php if(!empty($_post['service'])) { $i = 0; $selarr = array(); //i took array store these check box values ?> <table> <?php foreach($_post['service'] $key=>$service) { ?> <tr><td><?php echo $key; ?></td><td><?php echo $service; ?></td></tr> <?php } ?> </table> <?php }
i hope helps you.
Comments
Post a Comment