Greetings, I have been attempting to make a drop down menu of countries. From this menu I wish to create a variable in order to INPUT into mysql database. I have no trouble making the drop down menu, but I am unable to store a variable for it.
Here is a rough copy of what I am making:
<html>
<head>
<title>Add New MySQL User</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
if(isset($_POST['add']))
{
include 'c:\sokkit\config.php';
include 'c:\sokkit\opendb.php';
$username = $_POST['username'];
$password = $_POST['password'];
$query = "INSERT INTO account (username, password, location) VALUES ('$username', '$password', '$country')";
mysql_query($query) or die('Error, insert query failed');
$query = "FLUSH PRIVILEGES";
mysql_query($query) or die('Error, insert query failed');
include 'c:\sokkit\closedb.php';
echo "New MySQL user added";
}
else
{
?>
<form name="myform" action="http://www.mydomain.com/myformhandler.cgi" method="POST">
<div align="left">
<select name="mydropdown">
<option value="Milk">Fresh Milk</option>
<option value="Cheese">Old Cheese</option>
<option value="Bread">Hot Bread</option>
</select>
</div>
</form>
<form method="post">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Username</td>
<td><input name="username" type="text" id="username"></td>
</tr>
<tr>
<td width="100">Password</td>
<td><input name="password" type="text" id="password"></td>
</tr>
<tr>
<td width="100"> </td>
<td> </td>
</tr>
<tr>
<td width="100"> </td>
<td><input name="add" type="submit" id="add" value="Add New User"></td>
</tr>
</table>
</form>
<?
}
?>
</body>
</html>
As you can see my mysql Insert command here:
$query = "INSERT INTO account (username, password, location) VALUES ('$username', '$password', '$country')";
I set it using the variable $country. But i have no way to store the variable from here:
<div align="left">
<select name="mydropdown">
<option value="Milk">Fresh Milk</option>
<option value="Cheese">Old Cheese</option>
<option value="Bread">Hot Bread</option>
</select>
</div>
If someone could assist me in creating a stored variable from this drop down menu in order to INSERT into mysql database I would greatly appreciate it.
This is the return error when php script is run.
Notice: Undefined variable: country in C:\sokkit\site\Accounts\dummy.php on line 17
New MySQL user added