我在 May flutter 应用程序中遇到了一个问题,即我制作了一个 PHP 代码以在我的 00webhost 数据库中插入一个用户,该应用程序运行良好并返回:{seccess register,1 }b ut 非信息插入我的数据库任何帮助请
PHP 代码为:
<?php
include "db.php";
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With");
$name=$_POST['name'];
$email=$_POST['email'];
$pass=sha1($_POST['password']);
try {
if (isset($name,$email,$pass)) {
$req=$db->prepare("INSERT INTO users values(null,?,?,?)");
$req->execute(array($nme,$email,$pass));
if($req){
$secces=1;
$msg="seccess register";
}else{
$secces=0;
$msg="error register";
}
}else{
$secces=0;
$msg="error Empty Data";
}
} catch (\Throwable $th) {
$msg ="error: ".$th ->getMessage();
}
echo json_encode([
"result"=>[
$msg,
$secces
]
]);
?>
现在在下面的代码中它总是向我展示:{data: [email alredy excist, 0]} 但是我的数据库中的表 user 中没有任何内容:
<?php
include "db.php";
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With");
$name=$_POST['name'];
$email=$_POST['email'];
$pass=sha1($_POST['password']);
try {
if (isset($name,$email,$pass)) {
$req=$db->prepare("SELECT * from users where email=?");
$req->execute(array($email));
$exist = $req->rowCount();
if($exist=0){
$req=$db->prepare("INSERT INTO users values(null,?,?,?)");
$req->execute(array($nme,$email,$pass));
if($req){
$secces=1;
$msg="seccess register";
}else{
$secces=0;
$msg="error register";
}
}else{
$secces=0;
$msg="email alredy excist";
}
}else{
$secces=0;
$msg="error Empty Data";
}
} catch (\Throwable $th) {
$msg ="error: ".$th ->getMessage();
}
echo json_encode([
"result"=>[
$msg,
$secces
]
])
?>
?>