This question isn’t really about what’s wrong with some code. It’s about how to go about doing something. This is why no code is posted. Is there a way to run a specific MySQL query based on what’s selected in an HTML select box? Does a form have to be used here or is there another way?
I have now added the code and have tried using the switch statement way; however, the two textboxes are not being populated. Any ideas? The text in between the dashed lines isn’t really in the code but just a placeholder for the purpose of the question.
<?php
---db login info here---
switch($_GET['string'])
{
case "another string":
$query = mysql_query("SELECT field1 FROM table1 WHERE id = '1'");
$row = mysql_fetch_row($query);
break;
}
echo "<script type='text/javascript'>";
echo "document.getElementById('textbox').value = '$row[0]'";
echo "document.getElementById('textbox2').value = '$row[1]'";
echo "</script>";
?>
Yes, its possible. You can use forms or javascript URL call or ajax to perform this operation.
What you need to do it, based on the value selected in the selectbox, you need to run the sql statement in a switch case or if conditions.
The best option would be switch case for these kind of operations.
Hope this helps.