我有3张员工,主管,技师。
因此,管理员可以将所有用户添加到系统中,但我无法在表格中添加“首席”,这是我的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);
我无法理解为什么'首席'特别。
答案 0 :(得分:0)
status
是MySQL KEYWORD。所以我在查询中添加了回拨号(`)。
从
改变$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')";