I have
- A dropdown list populated from a MySQL table.
- A button.
- Another php page
What I need to do:
On clicking the button, pass the value selected from the dropdown list as a variable to second php page.
Pass that variable into a mysql query on the second php page. eg: $result = mysql_query("Select * from table where name like "$drop_down_value");
I am new to php and pardon my naivety.
This is my code to get values for the dropdown list:
function dropdown_query()
{
mysql_connect("localhost","root","root") or die("Failed to connect with database!!!!");
mysql_select_db("student_test") or die("cannot select DB");
$result = mysql_query("Select * from marks");
if($result=== FALSE){
die(mysql_error());
}
while($r=mysql_fetch_array($result))
{
echo '<option value="' .$r['marks'] . '">' . $r['marks'] . '</option>';
}
and this is my HTML part:
select name="dropdown" onchange="somefunc()">
<option value="">Select...</option>
<?php dropdown_query()?>
</select>
Lets say I use a similar query on another php. But would use the value selected on this page as a variable in that query.