gpt4 book ai didi

php - 使用 PHP、MySQL 和 SQLite 登录和注册

转载 作者:行者123 更新时间:2023-11-29 21:56:18 25 4
gpt4 key购买 nike

我正在练习在移动应用程序中开发登录和注册,但也集成在网络应用程序中,所以我正在关注这个:http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/

但是当在本地主机上运行时,输出显示:

{"error":true,"error_msg":"Required parameters (name, email or password) is missing!"}

这是源代码:

// json response array
$response = array("error" => FALSE);

if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['password'])) {

// receiving the post params
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];

// check if user is already existed with the same email
if ($db->isUserExisted($email)) {
// user already existed
$response["error"] = TRUE;
$response["error_msg"] = "User already existed with " . $email;
echo json_encode($response);
} else {
// create a new user
$user = $db->storeUser($name, $email, $password);
if ($user) {
// user stored successfully
$response["error"] = FALSE;
$response["uid"] = $user["unique_id"];
$response["user"]["name"] = $user["name"];
$response["user"]["email"] = $user["email"];
$response["user"]["created_at"] = $user["created_at"];
$response["user"]["updated_at"] = $user["updated_at"];
echo json_encode($response);
} else {
// user failed to store
$response["error"] = TRUE;
$response["error_msg"] = "Unknown error occurred in registration!";
echo json_encode($response);
}
}
}
else {
$response["error"] = TRUE;
$response["error_msg"] = "Required parameters (name, email or password) is missing!";
echo json_encode($response);
}
?>

最佳答案

使用此代码登录

<?php
//response array
$response = array("error" => FALSE);
if (isset($_POST['btn_name']))
{
// receiving the post params
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
if($name!="" && $email!="" && $password!="")
{
// check if user is already existed with the same email
if ($db->isUserExisted($email)) {
// user already existed
$response["error"] = TRUE;
$response["error_msg"] = "User already existed with " . $email;
echo json_encode($response);
} else {
// create a new user
$user = $db->storeUser($name, $email, $password);
if ($user) {
// user stored successfully
$response["error"] = FALSE;
$response["uid"] = $user["unique_id"];
$response["user"]["name"] = $user["name"];
$response["user"]["email"] = $user["email"];
$response["user"]["created_at"] = $user["created_at"];
$response["user"]["updated_at"] = $user["updated_at"];
echo json_encode($response);
} else {
// user failed to store
$response["error"] = TRUE;
$response["error_msg"] = "Unknown error occurred in registration!";
echo json_encode($response);
}
}
}
else {
$response["error"] = TRUE;
$response["error_msg"] = "Required parameters (name, email or password) is missing!";
echo json_encode($response);
}
}

?>

使用 PDO 和 OOP 的登录和注册脚本请访问此网址以获取说明:Login And Registration using Pdo In php and MySql

关于php - 使用 PHP、MySQL 和 SQLite 登录和注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33128572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com