2014-12-03 85 views
2

有一個下拉列表的表單。一旦用戶提交表單,我怎樣才能獲得用戶選擇到我的數據庫中的價值?無法獲取下面的代碼來存儲用戶選擇的值?謝謝你的幫助。如何將表單下拉列表選定值存儲到mysql數據庫中

FORM

<form action="xxx.php" class="well" id="xxx" name"xxx" method="post"> 


<select name="extrafield5"> 
<option value="NOW" selected="selceted">Submit order now</option> 
<option value="REVIEW">Submit my order for review</option> 
</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

http://oi60.tinypic.com/9ppc0i.jpg

+1

你應該包括更多的代碼。