Jump to content

$_POST variable question


gudmunson

Recommended Posts

Hey guys,

 

I have a question. I have an interesting scenario where I have multiple checkboxes sent via post to a next page. they are with name="checkbox1", name="checkbox2", etc. How do I access those on the next page? There could be quite a few of them, so I need to use a loop. I was hoping to access them via this method, but it doesn't seem to work. Any ideas?

 

$_POST['checkbox' .$i]

Link to comment
https://forums.phpfreaks.com/topic/44968-_post-variable-question/
Share on other sites

Change the names into arrays like:

A <input name="checkbox[1]" type="checkbox" value="A"><br>
B <input name="checkbox[2]" type="checkbox" value="B"><br>
C <input name="checkbox[3]" type="checkbox" value="C"><br>
D <input name="checkbox[4]" type="checkbox" value="D"><br>

Then you can access them like:

<?php
if (isset($_POST['checkbox']))
   foreach ($_POST['checkbox'] as $k => $v)
           echo 'Checkbox ' . $k . ' was checked. The value is ' . $v . '<br>';
?>

 

Ken

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.