check username and email already exists in php mysql

后端 未结 3 1534
隐瞒了意图╮
隐瞒了意图╮ 2020-12-18 17:14

check username and email already exists in php mysql,I have check every input is empty or not and if there is no empty then check username and password is already in databas

3条回答
  •  囚心锁ツ
    2020-12-18 18:03

    You only need to add else condition at right place

    Try this:-

    ';
            }
            if (isset($_POST['email']) && !empty($_POST['email'])) {
                $email=mysqli_real_escape_string($conn,trim($_POST['email']));
            }else{
                $error =1;
                $empty_email="Email cannot be empty.";
                echo $empty_email.'
    '; } if (isset($_POST['category']) && !empty($_POST['category'])) { $category=mysqli_real_escape_string($conn,trim($_POST['category'])); }else{ $error = 1; $empty_category="Category cannot be empty."; echo $empty_category.'
    '; } if (isset($_POST['password']) && !empty($_POST['password'])) { $psw=mysqli_real_escape_string($conn,trim($_POST['password'])); }else{ $error = 1; $empty_password="Password cannot be empty"; echo $empty_password.'
    '; } if (isset($_POST['re_password']) && !empty($_POST['re_password'])) { $repsw=mysqli_real_escape_string($conn,trim($_POST['re_password'])); }else{ $error = 1; $empty_repassword="Retype password cannot be empty"; echo $empty_repassword.'
    '; } $password=password_hash('$psw',PASSWORD_BCRYPT); $date=mysqli_real_escape_string($conn, trim('now()')); if($psw!=$repsw) { echo "password not Matched"; } if(!$error) { $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 { //here you need to add else condition echo "alright"; } } } ?>

提交回复
热议问题