Jump to content

Selecting multiple checkboxes


Andrew R

Recommended Posts

Hi

I am having trouble writing a script that will select multiple flight ids (from a checkbox) and process them into another page via the $_POST function

So for example I select flight id (RFS1869 and RFS5697 from the checkbox) and it will display information about these two results in another page.

Can anybody point me in to any tutorials or anything that will help with learn how to do this.

Cheers
Link to comment
Share on other sites

in your form:
[code]
<form action='target.php' method='post'>
  <input type = 'checkbox' name = 'somevar[]' value = 'rfs1869'> rfs1869 <br>
  <input type = 'checkbox' name = 'somevar[]' value = 'rfs5697'> rfs5697 <br>
  <input type = 'submit' value='submit'>
</form>
[/code]

target.php
[code]
$somevar = $_POST['somevar'];

// example
foreach ($somevar as $val) {
  echo "$val <br>"; // echo out each element in $somevar array
}

//another example
echo $somevar[0]; //echos first checkbox that was checked
echo $somevar[1]; //echos 2nd checkbox that was checked
[/code]
Link to comment
Share on other sites

If you want to get the values for the checkboxes from the database, then you can do it like this: [code]while($row = mysql_fetch_assoc($query_result)
{
echo "\t<label><input type='checkbox' name='flight_ids[]' value='{$row['value']}' /> {$row['user_readable_name']}</label>\n";
}[/code]
Link to comment
Share on other sites

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.