我正在制作帮助台票务系统。将下拉列表中的数据与从数据库表列中选择的值插入数据库表似乎存在问题。我正在使用PHP PDO和MySQL。
我的选择下拉列表如下所示:
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Department <span class="required">*</span></label>
<div class="col-md-9 col-sm-9 col-xs-12">
<select class="form-control" name="department" required>
<option value="" disabled selected></option>
<?php
$department_query = "SELECT * FROM department";
$stmt = $db->prepare($department_query);
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
echo "<option value='".$row['$department']."''>".$row['department']."</option>";
}
?>
</select>
</div>
</div>
它已经可以在下拉选项中读取和显示数据department_name
。
为了从我的表单中插入值,它可以从下拉列表中插入其他值EXCEPT。
我插入的内联php代码是:
<?php
if(isset($_POST['addticket'])){
$stmt = $db->prepare("INSERT INTO ticket (requestor_name, employee_name, department_concern, subject, description, priority) VALUES (:Requestor, :Employee, :Department, :Subject, :Description, :Priority)");
$stmt->bindParam(':Requestor', $Requestor);
$stmt->bindParam(':Employee', $Employee);
$stmt->bindParam(':Department', $Department);
$stmt->bindParam(':Subject', $Subject);
$stmt->bindParam(':Description', $Description);
$stmt->bindParam(':Priority', $Priority);
$Requestor = $_POST['requestor'];
$Employee = $_POST['employee'];
$Department = $_POST['department'];
$Subject = $_POST['subject'];
$Description = $_POST['description'];
$Priority = $_POST['priority'];
$stmt->execute();
}
?>
没有任何错误,但是我的数据库中没有插入选择下拉列表的值,而是插入了其他值。见下图。
我已尝试更改name=""
,$_POST['']
数百次 - 仍然是相同的结果,我无法找到答案。
我想要的只是显示
"<option value='".$row['$department']."''>".$row['department']."</option>"
这
<select class="form-control" name="department" required>
到
$Department = $_POST['department'];
以便它可以插入我的数据库。
如果有人能帮助我,那就太棒了。请。 提前谢谢你:)
答案 0 :(得分:0)
<option value="" disabled selected></option>
从您的选项中删除已禁用