pam
August 10, 2016, 7:53am
1
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
SamA74
August 10, 2016, 8:33am
2
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.
pam
August 10, 2016, 8:59am
3
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
pam
August 10, 2016, 9:03am
5
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
?
pam
August 10, 2016, 9:06am
7
if(isset($_POST[‘forward’]))
{
echo $forward= $_POST['select'];
die();
}
code of so_entry2.php
SamA74
August 10, 2016, 9:09am
9
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>
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.
pam
August 10, 2016, 9:16am
12
it still not working dude…
SamA74
August 10, 2016, 9:20am
13
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') {}
pam
August 10, 2016, 9:24am
14
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
SamA74
August 10, 2016, 9:26am
16
That may be it, the name should be unique.
pam
August 10, 2016, 9:30am
17
i test the code… for single forward options it is correct but for multiple options its nt working
SamA74
August 10, 2016, 9:33am
19
pam:
i test the 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
pam
August 10, 2016, 9:34am
21
validator is correctly working