i have a dropdown
and the items of the dropdown
Filling dynamic, i looking for a way to send selected value to server using php not ajax i have a <form>
and submit button, have to access the selected value on server, this is my code:
<form action="singer.php" method="post">
<table>
<tr>
<td>سبک</td>
<td><select name="genre_list">
<?php
include('../db_inc.php');
$sql="select * from genre";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_object($result)){
$option =$row->genre_name;
$value =$row->genre_id;
echo '<option value='.$value.'>'.$option.'</option>';
}
?>
</select></td>
</table>
</form>
i'm googled this issue but i can't find the solution,
If you submit to the current file, you will see the selected form by using $_POST['genre_list']
If you want to send the user selected value, you should check where does $_POST['genre_list']
appears at the while-loop
and then add to his <option>
the attribute selected="selected"
so it should look like
$isSelected = ($_POST['genre_list'] == $row['COLUMN-NAME'] ? "selected='selected' " : "");
echo '<option $isSelected value='.$value.'>'.$option.'</option>';
Do not forget to avoid SQL-Injection when getting values from user client.
have it output the variable for the value surrounded with quotes "
echo '<option value="'.$value.'">'.$option.'</option>';
then use: $_POST['genre_list']
to show the selected genre_id
In singer.php, $_POST['genre_list']
should contain the value from the SELECT.