Jump to content

Recommended Posts

I have this code that generates fields:

$order=0;
$count2=1;
while($order < $count)
{
echo "<input type='checkbox' name='".$country[$order]."' value = ' ".$count2."'>".$country[$order]. "<br />";
$order++;
$count2++;
}

 

I would like to get checked checkboxes values to variables into code below:

<?php
if (isset($_POST['continue']))
{
   //I need to have the checked values to variables here
}
?>

 

any help?

Link to comment
https://forums.phpfreaks.com/topic/130414-solved-get-post-fileds/
Share on other sites

okay.. first change

echo "<input type='checkbox' name='".$country[$order]."' value = ' ".$count2."'>".$country[$order]. "<br />";

to

echo "<input type='checkbox' name='myorders[]' value = ' ".$count2."'>".$country[$order]. "<br />";

myorders can be anything just make sure you have the brackets []

 

now to display

<?php
if (isset($_POST['continue']))
{
   //I need to have the checked values to variables here
   foreach($_POST['myorders'] as $mo)
   {
      //only the check boxes appear
      echo "$mo<br>";
   }
}
?>

 

*untested but should be fine

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.