我正在尝试登记表格,有人可以查看并告诉我这里有什么问题吗?
我正在使用Postman对其进行测试,并且它总是向我显示以下错误:
{"error":true,"message":"Required fields are missing"}
我的DbOperations.php
//For Employee Registration
public function emplReg($name, $surname, $username, $user_pass, $address, $pin, $mail, $phone){
$password = md5($user_pass);
$stmt = $this->con->prepare("INSERT INTO `emp_data` (`name`, `surname`, `username`, `password`, `address`, `pin`, `mail`, `phone`) VALUES ('?', '?', '?', '?', '?', '?', '?', '?');");
$stmt->bind_Param("ssssssss",$name,$surname,$username,$user_pass,$address,$pin,$mail,$phone);
if ($stmt->execute()) {
return 1;
}else{
return 2;
}
}
和我的emplReg.php
<?php
require_once '../include/DbOperations.php';
$response = array();
if($_SERVER['REQUEST_METHOD']=='POST'){
if(
isset($_POST['reg_name']) and isset($_POST['reg_surname']) and isset($_POST['reg_username']) and isset($_POST['reg_password']) and isset($_POST['reg_address']) and isset($_POST['reg_pin']) and isset($_POST['reg_mail']) and isset($_POST['reg_phone'])
){
//operate the data further
$db = new DbOperations();
$result = $db->emplReg( $_POST['reg_name'],
$_POST['reg_surname'],
$_POST['reg_username'],
$_POST['reg_password'],
$_POST['reg_address'],
$_POST['reg_pin'],
$_POST['reg_mail'],
$_POST['reg_phone']
);
if($result == 1){
$response['error'] = false;
$response['message'] = "User register successfully";
}elseif($result == 2){
$response['error'] = true;
$response['message'] = "Something wrong, try again";
}
}else{
$response['error'] = true;
$response['message'] = "Required fields are missing";
}
}else{
$response['error'] = true;
$response['message'] = "Invalid Request";
}
echo json_encode($response);
?>
答案 0 :(得分:1)
我发现你做错了三件事......
x-www-form-urlencoded
代替form-data
。$user_pass
更改为$password
。'?'
?
中删除引号。