$sql = $conn->prepare("SELECT username, email FROM users WHERE username=? OR email = ?");
$sql->bind_param('ss', $uname, $email);
$sql->execute();
$result = $sql->get_result();
$row = $result->fetch_array(MYSQLI_ASSOC);
if ($row['username'] == $uname) {
echo "Username not availabe try different";
} elseif ($row['email'] == $email) {
echo "email is already taken diiferent";
} else {
$stmt = $conn->prepare("INSERT INTO users (username, email, pass, created) VALUES (?, ?, ?, ?)");
$stmt->bind_param('ssss', $username, $email, $pass, $created);
if ($stmt->execute()) {
echo "Registrated sucessfully. Login Now!";
} else {
echo "Something went wrong. Please try again";
}
}
此代码未运行。我不知道为什么。如果我正在获取单行,那么它正在工作,但对于多行它不工作。
在这里,我想使用准备好的语句验证数据库中是否已经存在用户名和电子邮件。