I am creating a form which when submitted sends the output to an INSERT statement. I am learning how to do this using:
<form action="somepage.php" method="post">
Example: <input type="text" name="something" />
<input type="submit" />
</form>
I am fairly comfortable doing this and then writing an INSERT statement containing $_POST.
I also have a field that I would like to present in a drop down which is populated with the results of a mysql_query, as below:
$sql = "SELECT name FROM customer";
$result4 = mysql_query($sql);
echo "<select name='name'>";
while ($row = mysql_fetch_array($result4)) {
echo "<option value='" . $row['name'] . "'>" . $row['name'] . "</option>";
}
echo "</select>";
However I am not sure how to use the value that the user selects. I.e. I would like to use the value that they select in my INSERT statement along with the other form fields.
How do I do this?
mysql_*functions in new code. They were removed from PHP 7.0.0 in 2015. Instead, use prepared statements via PDO or MySQLi. See Why shouldn't I use mysql_* functions in PHP? for more information.