I have a drop down list which is dynamically populated from a MySQL database :
<select name= "studentnames" >
<option value="0">Select a Student</option>
$RSStudentName = mysql_query( "SELECT StudentName, StudentID FROM Students " );
while($StudentNameList = mysql_fetch_object($RStudentName))
{
<option value = "<?php echo $StudentNameList->StudentID ;?> " >
<?php
echo $StudentNameList->StudentName ;
?>
</option>
<?php
}
?>
</select>
The drop down gets filled these items as below :
Student1
Student2
Student3
Student4
Student Table is as :
SID | SNAME
S001 | Student1
S002 | Student2
S003 | Student3
Now when the users selects a student name from the drop down list, i want to get the value of that option , and insert it into a table. How to do this?
That is, if user selects Student3 in the drop down list, then i want to get S003 in some variable and insert it in a table? Please help with how to get the value attribute in a variable.
Could this be done?
$sid = $_POST('studentnames').value;
If it’s a simpel form post: the selected value will be in:
In your code, use the ID as VALUE, and the name just as text
then
will contain the is, might be better then naming it simply ‘student’…