檢查用戶名和電子郵件已經存在於php mysql中,我檢查每個輸入是否爲空或如果沒有空然後檢查用戶名和密碼是否已經在數據庫中,如果它不在數據庫中,然後回顯ALRIGHT,代碼工作正常,但問題是,它不打印好吧當新的條目進行。檢查用戶名和電子郵件已存在於php mysql
下面是代碼:
<?php
error_reporting(E_ALL & ~E_NOTICE);
require_once('dbcon.php');
if(isset($_POST["create"]))
{
if (isset($_POST['username']) && !empty($_POST['username'])) {
$username=mysqli_real_escape_string($conn,trim($_POST['username']));
}else{
$empty_username="Username Cannot be empty.";
echo $empty_username.'<br>';
}
if (isset($_POST['email']) && !empty($_POST['email'])) {
$email=mysqli_real_escape_string($conn,trim($_POST['email']));
}else{
$empty_email="Email cannot be empty.";
echo $empty_email.'<br>';
}
if (isset($_POST['category']) && !empty($_POST['category'])) {
$category=mysqli_real_escape_string($conn,trim($_POST['category']));
}else{
$empty_category="Category cannot be empty.";
echo $empty_category.'<br>';
}
if (isset($_POST['password']) && !empty($_POST['password'])) {
$psw=mysqli_real_escape_string($conn,trim($_POST['password']));
}else{
$empty_password="Password cannot be empty";
echo $empty_password.'<br>';
}
if (isset($_POST['re_password']) && !empty($_POST['re_password'])) {
$repsw=mysqli_real_escape_string($conn,trim($_POST['re_password']));
}else{
$empty_repassword="Retype password cannot be empty";
echo $empty_repassword.'<br>';
}
$password=password_hash('$psw',PASSWORD_BCRYPT);
$date=mysqli_real_escape_string($conn, trim('now()'));
if($psw!=$repsw)
{
echo"password not Matched";
}
$sql="select * from account_info where (username='$username' or email='$email');";
$res=mysqli_query($conn,$sql);
if (mysqli_num_rows($res) > 0) {
// output data of each row
$row = mysqli_fetch_assoc($res);
if ($username==$row['username'])
{
echo "Username already exists";
}
elseif($email==$row['email'])
{
echo "Email already exists";
}
else{
echo "alright";
}
}
}
?>
好吧,有什麼問題了嗎? –
執行代碼的結果是什麼,以及您希望得到的結果 – SaggingRufus
幾乎可以工作,但是當我提供新的用戶名和電子郵件時,不會打印出「沒問題」的數據庫。對我的英語來說, – learner