gpt4 book ai didi

PHP 检查数据库中的用户 ID

转载 作者:行者123 更新时间:2023-11-29 12:48:37 25 4
gpt4 key购买 nike

我正在使用 jquery ajax 将数据发送到 php 文档。对用户输入的第一个检查 ($check_user_exists) 是查看同一 $email 下是否有帐户。我尝试在 if 语句之前编写一个函数,但这也不起作用。

我收到以下错误:

Parse error: syntax error, unexpected 'return' (T_RETURN) in C:\xampp\htdocs\workflow\ajax\register.php on line 8

提前致谢!代码如下:

if (isset($_POST['email']) && isset($_POST['firstname']) && isset($_POST['lastname']) && isset($_POST['role']) && isset($_POST['pw'])){
$email = strtolower($_POST['email']);
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$pw = crypt($_POST['pw'], md5($email));
$role = $_POST['role'];
$check_user_exists = return (mysql_result(mysql_query("SELECT `user_id` FROM `users` WHERE user_id = '$email.'"), 0)==1) ? true : false;
if($check_user_exists === true){
echo 'Our records show an account already exists under this email.';
}

最佳答案

这样做:

$email = mysql_real_escape_string(strtolower($_POST['email']));
$firstname = mysql_real_escape_string($_POST['firstname']);
$lastname = mysql_real_escape_string($_POST['lastname']);
$pw = crypt($_POST['pw'], md5($email));
$role = mysql_real_escape_string($_POST['role']);
$result = mysql_query("SELECT COUNT(*) AS count FROM `users` WHERE user_id = '$email'") or die(mysql_error());
$row = mysql_fetch_assoc($result);
$check_user_exists = $row['count'];
if ($check_user_exists > 0){
echo 'Our records show an account already exists under this email.';
} else {
mysql_query("INSERT INTO users (user_id, firstname, lastname, pw, role)
VALUES ('$email', '$firstname', '$lastname', '$pw', '$role')") or die(mysql_error());
echo 'User added successfully.';
}

关于PHP 检查数据库中的用户 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25070834/

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