Have a form with a dropdown select box list. How can I store the value of a user selected option from a drop down select box list into mysql database? Thanks.
FORM
<form action="xxx.php" class="well" id="xxx" name"xxx" method="post">
<select name="extrafield5">
<option value="NOW" selected="selected">Submit order now</option>
<option value="REVIEW">Submit my order for review</option>
<button id="btn1" type="submit" value="Submit">Submit</button>
</select>
</form>
PHP FILE
<?php
define('DB_NAME', 'xxx');
define('DB_USER', 'xxx');
define('DB_PASSWORD', 'xxx');
define('DB_HOST', 'xxx');
$connection = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$connection){
die('Database connection failed: ' . mysqli_connect_error());
}
$db_selected = mysqli_select_db($connection, DB_NAME);
if(!$db_selected){
die('Can\'t use ' .DB_NAME . ' : ' . mysqli_connect_error());
}
echo 'Connected successfully';
if (isset($_POST['extrafield5'])){
$extrafield5 = $_POST['extrafield5'];
}
else {$extrafield5 = '';}
$sql = "INSERT INTO seguin_orders (extrafield5)
VALUES ('$extrafield5')";
if (!mysqli_query($connection, $sql)){
die('Error: ' . mysqli_connect_error($connection));
}
DATABASE
You can't go to the next page (xxx.php) until you submit the form. So please put submit button in the form.
It will resolve the issue.
You need to submit the form.
And get it in PHP: