答案 0 :(得分:1)
您需要将值绑定到预准备语句。您可以使用$statement->bindValue(':placeholder', $value)
您的代码看起来像这样:
$stmt = $conn->prepare("INSERT INTO pc_rig (customer,email,processor,gpu,procfan)
VALUES (:customer, :email, :processor, :gpu, :procfan)");
$stmt->bindValue(':customer', $customer);
$stmt->bindValue(':email', $email);
$stmt->bindValue(':processor', $selectOption);
$stmt->bindValue(':gpu', $selectOption1);
$stmt->bindValue(':procfan',selectOption1);
$stmt->execute();
答案 1 :(得分:0)
<form action ="pagename.php" name="formname" method = "POST">
<select name="processor" id="processor">
<option selected="select1">Please select...</option>
<option selected="select1">Please select...</option>
<option value="intel_high">Intel i5</option>
<option value="intel_mid">Intel Pentium</option>
<option value="intel_low">Intel Core2Duo</option>
<option value="amd_high">AMD A6</option>
<option value="amd_mid">AMD Anthlon</option>
<option value="amd_low">AMD Geode</option>
</select>
<input type="submit" name="submit" value="Insert">
</form>
<?php
$selectOption = $_POST['processor'];
require ("connect.php");
$stmt = $conn->prepare("INSERT INTO pc_rig (processor)VALUES('$selectOption')");
$stmt->execute ();
header ('Location:rig_finish_list.php');
?>
了解更多http://indiainfotip.com/insert-drop-down-list-selected-value-to-mysql-db-using-php/