Error in POST selected option value

i post this form into the next php page but only the by default value is posting plz help me to solve dis

<FORM name='myForm' method='post' id="myForm" action="so_entry2.php">
            
              <select name='select' class='selectpicker' id='select'>
                   <option value='0'><------select------></option>
                            
                  <?php $query11=pg_query($connect,"select emp_code, name from users where post='Dealing hand' ");
                  while ($stmt11 = pg_fetch_assoc($query11))
                    {  $emp_code=$stmt11["emp_code"];
                        $emp_name=$stmt11["name"];
                   
                    print" <option value='$emp_code'>$emp_name [$emp_code]</option>";
                     } ?>
           
              <option value='4'>DD</option>
          
            <option value='5'>JD</option>
             <option value='6'>Director</option>
            <option value='7'>VO</option>
            <option value='8'>CVO</option>
            
        </select>
            <button name=forward>Forward</button> 
   </form>  <?php if(isset($_POST['forward']))
{    
   echo   $forward= $_POST['select'];
}?>

when i select any options it posts only by default value that is 0
now in the next page that is on the so_entry2.php

here after clicking the button only 0 value is posting
Thanks in advance

What does the resulting html code for the form look like? Check that the while is working properly by checking the html of the select element.

yes while is working properly
my prblm is that select is posting by default first value

Is this where you get the zero output from?

   echo   $forward= $_POST['select'];

If so, isn’t that correct because $forward is not defined, and therefore will never be the same as your $_POST value?

1 Like

so whts the solution? please tell me

Well, that line of code is displaying the result of comparing $forward to the value of $_POST['select'] - do you want to do that in that location? I can’t see what function it would have, but then people don’t always put all their code up, so maybe there’s more after that bit.

Can you show the code for so_entry2.php?

if(isset($_POST[‘forward’]))
{

  echo   $forward= $_POST['select'];

die();
}

code of so_entry2.php

It’s a good idea to first sanitise the data, then you can echo the variable once it is defined.

$forward = preg_replace('#[^0-9]#i', '', $_POST["select"]) ; // if expecting an integer
echo $forward ; 

Also there is a minor html error to fix:-

<form>  <?php if(isset($_POST['forward']))

The closing form tag should have a slash: </form>

it still not working :frowning:

I still think you need to split this

  echo   $forward= $_POST['select'];

into

  $forward= $_POST['select'];
  echo $forward;

As I read it (which might not be correct), your echo() statement shows the result of assigning a value from the form to $forward, not the value of that form variable.

it still not working dude…

Your button name attribute is missing quotes (validate the html), also this should not be necessary, as submit should be the default type for a button, but to be safe:-

<button name="forward" type="submit">Forward</button> 

And a better test for form submission is:-

if ($_SERVER['REQUEST_METHOD'] == 'POST') {}

let me tell u one thing there are multiple forward options in the main page i guess it will unable to take the id that is which forward i m doing

Stick a hidden form variable in to decide which form was submitted, if they all go to the same place.

Any chance there are html typos in any of the rest of the code, like the incorrect closing form tag that @SamA74 noticed? That could affect things.

1 Like

That may be it, the name should be unique.

i test the code… for single forward options it is correct but for multiple options its nt working

show me some code

Did you run the html through the validator? I picked up a couple of errors, but if that’s not the whole page there may be more.

Sorry, do you mean that you have multiple forms on the page, and you have options within them, but only one of them gets passed through? If that’s true, then I don’t think it will work - you’d have to put them all within the same form.

Might be easier to figure out if you could show the actual html code that the php in the first post creates, as @SamA74 said earlier. You could cover the names up if you are concerned about security.

1 Like

validator is correctly working