How can i populate a mysql database with more than 1 dropdown lists ?
My code in html page is:
<form method="post" action="submit.php">
Number: <select name="number">
<option value="535">535</option>
<option value="338">228</option></select>
<br>
Name: <select name="name">
<option value="John">John</option>
<option value="Dave">Dave</option></select>
<br>
<input type="submit" value="Add" />
</form>
My code in php is:
$Number = $_POST['number'] ;
$Name = $_POST['name'] ;
$query = "INSERT INTO submit (Number,Name) VALUES ('number','name')";
mysql_query($query) or die('Error Updating Database');
echo "Added";
Yes, you can store the values from two different select lists in a MySQL query, but you need to actually insert the values that come back in
$Numberand$Namelike so:I have also added
mysql_real_escape_string()to help sanitise the user input before blindly inserting it into a database. This is a basic anti-SQL Injection measure.Of course you also need to already be connected to the MySQL server and have selected a database.