-2
我正在嘗試製作註冊表單,任何人都可以檢查並告訴我這裏有什麼問題?註冊功能不能正常顯示{「error」:true,「message」:「必填字段丟失」}
我使用郵差測試它,它總是向我展示以下錯誤:
{"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);
?>
https://www.dropbox.com/s/m0ngx8hqy6vr3t8/Untitled.png?dl=0
您是否通過郵遞員發送了所有必填字段? –
該錯誤消息僅在一個地方發生 - 在第二個if條件的else中。因此,合乎邏輯的結論是,不檢查它檢查的所有$ _POST值。 – CBroe
@PavloZhukov是... –