我有以下表格,但我无法在数据库中添加SELECT(具有多项选择的下拉菜单)值。我哪里错了? 我正在使用PHP,除了选择部分,我可以正确添加所有其他值。我想有一个带有一些选项的下拉菜单,当我按“提交”时,所选的值进入数据库。
<form action="post.php" method="post">
<div class="form-group">
<label for="name">Customer Name:</label>
<input type="text" name="name" class="form-control" id="name">
</div>
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" name="email" class="form-control" id="email">
</div>
<div class="form-group">
<label for="number">Mobile Number:</label>
<input type="text" name="number" class="form-control" id="number">
</div>
<div class="form-group">
<label for="price">Price:</label>
<input type="text" name="price" class="form-control" id="price">
</div>
<div class="form-group">
<label for="payment">Payment Type</label>
<input type="text" name="payment" class="form-control" id="payment">
</div>
<div class="form-group">
<label for="device">Device Name:</label>
<input type="text" name="device" class="form-control" id="device">
</div>
<div class="form-group">
<label for="status">Status:</label>
<select name="status[]" multiple class="form-control" id="status">
<option value="New">New</option>
<option value="Green">Progress</option>
<option value="Blue">Wait</option>
<option value="Pink">Done</option>
<option value="Yellow">Close</option>
</select>
</div>
<button type="submit" name="submit" class="btn btn-default">Submit</button>
</form>
和查询:
$sql = "INSERT INTO ... (name, mail, number, device, price, paymenttype,status,date) VALUES ('$name', '$email', '$number', '$device', '$price', '$payment','$status',NOW())";
if(mysqli_query($link, $sql)){
// echo "Records added successfully.";
header("location:....php?message=The customer has been added to the database");
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
答案 0 :(得分:1)
您必须更改以下HTML代码:
name="status[]"
要:
name="status"
另外,根据this,您应该在重定向页面后添加exit()
:
header("location:....php?message=The customer has been added to the database");
exit();