我想使用PHP,MySQL和Swift注册用户并登录该用户,但出现错误。
这是api.php
<?php
include"dbconfig.php";
$request = $_POST['request'];
//$request = 'register';
if($request == 'register'){
$email = $_POST['email'];
$password = $_POST['password'];
//$email = 'shubham@gmail.com';
//$password ='shubham';
$stmt = $db_con->prepare("INSERT INTO users VALUES (:email, :password)");
$stmt->bindParam(":email",$email);
$stmt->bindParam(":password",$password);
if($stmt->execute()){
$response['message'] = 'Registration Sucessfully Done..!!';
}else{
$response['message'] = 'Registration Faild..!!';
}
echo json_encode($response);
}
else if($request == 'login'){
$email = $_POST['email'];
$password = $_POST['password'];
$stmt = $db_con->prepare("SELECT * FROM users WHERE email = '".$email."' AND password = '".$password."'");
$stmt->execute();
if($stmt->rowCount()==0){
$response['error'] = true;
$response['message'] = 'Login Field..!!';
}else{
$response['error'] = false;
$response['message'] = 'User Login Sucesssfully..!!';
}
echo json_encode($response);
}
elseif($request == 'insert'){
$employeeID = $_POST['employeeID'];
$employeeName = $_POST['employeeName'];
$employeeDepartment = $_POST['employeeDepartment'];
$stmt = $db_con->prepare("INSERT INTO employee VALUES ( :employeeID, :employeeName,:employeeDepartment)");
$stmt->bindParam(":employeeID",$employeeID);
$stmt->bindParam(":employeeName",$employeeName);
$stmt->bindParam(":employeeDepartment",$employeeDepartment);
if($stmt->execute()){
$response['message'] = 'New Record are Added Sucessfully ..!!';
}else{
$response['message'] = 'New Record Add Faild..!!';
}
echo json_encode($response);
}
?>
这是我的dbconfig.php
<?php
$db_host = "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "phpfile";
try{
$db_con = new PDO("mysql:host={$db_host};$db_name",$db_user,$db_pass);
}catch(PDOException $e){
echo $e->getMessage();
}
?>
当我尝试在网络上运行此api.php文件时:
注意:未定义的索引:第5行/Applications/XAMPP/xamppfiles/htdocs/phpfile/api.php中的请求
我试图在Alamofire的帮助下使用Swift代码注册用户。
答案 0 :(得分:0)
'request' = 'register'