0

On my form I've got a select from a table. I've put it in a for loop so that each time the name of the select changes to option0, option1, etc. Then on the action page of the form I need to get the info for each option selected, eg $_POST['option0'], $_POST['option1'], etc to input it into a table. I can't get the action page to work, what am I doing wrong?

PAGE1

for ($x = 0; $x <= 14; $x++) { 
    $get2a = mysqli_query($con,"SELECT * FROM table");
    $opt = "<select name='interviewer". $x . "'>";
    while($row2a = mysqli_fetch_array($get2a)) {
        $intvID = $row2a['intvID'];
        $opt .= "<option value = '";
        $opt .= $row2a['intvID'];
        $opt .= "'>";
        $opt .= $row2a['intvID'];
        $opt .= "</option>";
    }

PAGE 2

for ($y = 0; $y <= 14; $y++) {
    echo $_POST['interviewer . $y . '];
}
1
  • it would help if you posted the generated html. I doubt you're generating something that would fit into $_POST['interviewer . $y . ']; Commented Jun 8, 2015 at 15:20

2 Answers 2

1

You are calling your selectable options sets $opt = "<select name='option". $x . "'>";

So Page2 should be looking for things names 'option0' ... 'option13'` like this

for ($y = 0; $y <= 14; $y++) {
    echo $_POST['option' . $y];    <-- notice slight syntax change also
}   
Sign up to request clarification or add additional context in comments.

1 Comment

Yes sorry about that, I changed it, thank you it is working now
1

Have you tried printing the post array? Use print_r:

print_r($_POST);

I don't believe the post has something that is named 'interviewer .... something.

besides, if you wish to mix text and variables, use

$_POST["interviewer {$x}"]

remove the single quotes and the dots. Single quotes do not evaluate variables:

$_POST['interviewer . $y . ']; -> wrong

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.