我有一个页面,为此我将订单分配给员工,我有一个下拉菜单,可从数据库中获取员工姓名,
这是代码:
<?php
$db = mysqli_connect('localhost', 'root', '', 'pms');
$sql = "SELECT emp_first_name, emp_id FROM employee";
$result = $db->query($sql);
echo "<select name='emp_id'>";
while ($row = mysqli_fetch_array($result)) {
echo "<option value='" . $row['emp_id'] ."'>" . $row['emp_first_name']. "(" . $row['emp_id']. ")</option>";
}
echo "</select>";
$db->close();
?>
在此代码中,如何获取员工ID并将其插入数据库中的“分配给”列中
这是更新表的命令:
if (isset($_POST['assign'])){
if (isset($_POST['checkbox'])){
$update = "update orders set assign_to = "$emp_id";
if($update){
echo(passed);
}
else{
echo "failed";
}
}
请填写剩下的查询,我是php新手
答案 0 :(得分:1)
You need to get the value of your droplist ffrom POST by using the droplist name
Do this
(isset($_POST['assign'])){
if (isset($_POST['checkbox'])){
$emp_id=$_POST['droplistname'];
$update = "update orders set assign_to = ?";
$stmt=$db->prepare($update);
$stmt->bind_param("s", $emp_id);
if($stmt->execute()){
echo "passed";
}
else{
echo $db->error;
echo "failed";
}
}