I am building a select option dynamically. I am selecting from the select option, one value. (values for list come from php How can I pass that selected value to PHP?
Solution 1:
I think I see what your problem is. You're not setting a select option.
Try this:
<?php $options = 'John' ;
?> <form id ="swimdata" method ="POST" action ="save.php" > <input type ="radio" style ="font-size: 16px;font-weight: bolder" name ="gender" class ="gender" value ="boys" > BOYS
<input type ="radio" style ="font-size: 16px;font-weight: bolder" name ="gender" class ="gender" value ="girls" > GIRLS
<table id ="meetTable" style ="width:auto" > <tr > <th > EVENT:</th > <th > NAME:</th > <th > LANE:</th > <th > TIME:</th > <th > PLACE:</th > <th > SCORE 1:</th > <th > SCORE 2:</th > <th > PLACE:</th > <th > TIME:</th > <th > LANE:</th > <th > NAME:</th > </tr > </table > <select id ="s1" name ="swimopt" class ="so" value ="" > <?php for ($i =0 ;$i <10 ;$i ++){
echo '<option value="user ' .$i .'" >user ' .$i .'</option>' ;
}
?> </select > <input type ="submit" name ="formSubmit" value ="Submit" /> <input type ="hidden" name ="action1" value ="addSwimmer" id ="action1" > </form >
Copy Solution 2:
The select option must be wrapped with html tag <option>
with a value
attribute, which will be posted if it is selected.
According to your given code you are not generating option
s for a select
. So try something like this:
if ($result ->num_rows > 0 ) {
$options = '' ;
while ($row = $result ->fetch_assoc()) {
$options .= "<option value=\"" . $row ["swimmer_id" ] ."\">" . $row ["first_name" ]. " " . $row ["last_name" ]. " - " . $row ["school_name" ]. "</option>" ;
}
} else {
echo "0 results" ;
}
echo $options ;
$conn ->close();
Copy Now if you $_POST
it you will get the swimmer id
Post a Comment for "How To Pass The Selected Value In Dropdown (html) To Php"