I am using html, PHP and MySQL to create a webpage that has a dropdown. The contents of the dropdown will be pulled from a MySQL database table. I am able to get the dropdown populated and I am able to get a search button created using PHP. My question is after selecting an entry from the dropdown how do I get the button to pull that info so I can do something else with it. In this case I want to do two things.
- Show the entry selected in the dropdown along with its associated information in the SQL table.
- have a second button that then sends you to a link based on the information collected from SQL.
In essence you select an 800 number from a dropdown. it shows you the 800 number and the name associated with the 800 number and then when you click a "go" button it sends you to their website.
All of the 800 number name associations exist in a SQL DB because it is dynamically changed.
Here's what I have so far:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
<?php
mysql_connect("localhost", "root", "root") or die("Connection Failed");
mysql_select_db("voice")or die("Connection Failed");
$query = "SELECT * FROM 800db";
$result = mysql_query($query);
?>
<form mthod="post">
<select id="8xx" name="dropdown1">
<?php
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
<option value="<?php echo $line['8xxNumber'];?>">
<?php echo $line['8xxNumber']; ?>
</option>
<?php } ?>
</select>
</form>
<?php
$selected_8xx = $_POST['8xx'];
echo
"<form action='' method='post'>
<input type='submit' name='use_button' value='search' />
</form>";
if(isset($_POST['use_button'])) {
echo "it should say $selected_8xx";
}
?>
</body>
</html>
I do not get the desired results. In fact when I click the button it reverts the dropdown back to the default value and returns nothing. Anything you can do to help would be appreciated.
<form mthod="post"><?php error_reporting(E_ALL); ini_set('display_errors', 1);then the rest of your code, to see if it yields anything. Also addor die(mysql_error())tomysql_query().