gpt4 book ai didi

php - 无法将用户添加到 MySQL

转载 作者:行者123 更新时间:2023-11-29 22:09:15 24 4
gpt4 key购买 nike

我有 3 个表,分别是员工、主管、技术员。

所以,管理员可以将所有用户添加到系统中,但我无法将“chief”添加到表中,这是我的 html。

               <form name="form" method="post" action="add_user_db.php">
<div class="control-group">
<label>Type of User</label>
<div class="controls">
<select class="form-control" name="filter" id="filter">
<option value="employee">Employee</option>
<option value="technician">Technician</option>
<option value="chief">Chief</option>
</select>...some other code..</form>

这是我添加用户的 php。

$filter = $_POST["filter"];     
$id = $_POST["id"];
$password = md5($_POST["password"]);
$name = $_POST["name"];
$department = $_POST["department"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$cellphone = $_POST["cellphone"];


if($filter =='chief'){
$sql = "INSERT into $filter (chief_id,password,chief_name,status,department,phone,cellphone,email) values ('$id', '$password', '$name', 'CHIEF', '$department', '$phone', '$cellphone', '$email')";
$dbquery = mysql_db_query("inform_db", $sql);

mysql_close();
header( "refresh:0.01;url=add_user.php" );

}
if($filter == 'employee'){
$sql = "INSERT into $filter (employee_id,password,name,status,department,phone,cellphone,email) values ('$id', '$password', '$name', 'USER', '$department', '$phone', '$cellphone', '$email')";
$dbquery = mysql_db_query("inform_db", $sql);

mysql_close();
header( "refresh:0.01;url=add_user.php" );

}
if($filter == 'technician'){
$sql = "INSERT into $filter (tech_id,password,tech_name,status,phone,cellphone,email) values ('$id', '$password', '$name', 'TECH', '$phone', '$cellphone', '$email')";
$dbquery = mysql_db_query("inform_db", $sql);

我不明白为什么特别是“酋长”。

最佳答案

status 是 MySQL 关键字。所以我只是在查询中添加了反勾(`)。

更改自

$sql = "INSERT into $filter (chief_id,password,chief_name,status,department,phone,cellphone,email) values ('$id', '$password', '$name', 'CHIEF', '$department', '$phone', '$cellphone', '$email')";

$sql = "INSERT into $filter (chief_id,password,chief_name,`status`,department,phone,cellphone,email) values ('$id', '$password', '$name', 'CHIEF', '$department', '$phone', '$cellphone', '$email')";

关于php - 无法将用户添加到 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31852181/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com