Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Passing Checkbox values in PHP?

I am trying to pass a form in PHP between pages using $_POST. I'm getting snagged up on the check boxes. I've tried a few things here's my latest attempt...

The error is... Notice: Undefined index: field_trip

Here's some code.

On the form page... <input type="checkbox" name="field_trip[]" id="field_trip[]" value="saline" />

On the next page... I've tried...

$trip = $_POST['field_trip'];

Also...

if(isset($_POST['field_trip']))

{ echo "stuff";}

Also..

if($_POST['field_trip'] != "")

{do stuff}

None of it seems to work. I've also used field_trip[] on the second page to no avail.

Help please.

Update:

to the first answer...

No... first the syntax is $_POST

Secondly as I said in my question I get an error when I try to assign $_POST['field_trip'] to a variable.

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    Ok, not sure if this will solve your problem, but here's my thoughts:

    -Drop the id parameter in your input. If you need an id, don't use the brackets at the end.

    -double check your form...make sure you're using post and all that.

    All I could think of, it should work...but, the catch:

    Find out what version of PHP you are using. There's a chance the error can simply be turned off or something. Check out the source links below. I've found some discussions about erorr reporting.

  • 1 decade ago

    Page 1:

    <input type="checkbox" name="field_trip[]" value="value1">Value 1

    <input type="checkbox" name="field_trip[]" value="value2">Value 2

    <input type="checkbox" name="field_trip[]" value="value3">Value 3

    Page 2:

    $field_trip = $POST['field_trip'];

    foreach ($field_trip as $value) {

    # work here

    }

Still have questions? Get your answers by asking now.