Summer Sale! All accounts are 50% off this week.

sultanwebdev's avatar

How to to chek user email and phone Already In database email & phone validation

<?php

$connect = mysqli_connect("localhost","root","", "connect_my");
   
    if(isset($_POST['send'])){
        $name = $_POST['name'];
        $email = $_POST['email'];
        $phone = $_POST['phone'];
        $dept = $_POST['dept'];



        $email_select = "SELECT * FROM insert_data WHERE email = '$email'";

    

        $exc = mysqli_query($connect, $email_select);
        $count =mysqli_num_rows($exc);
        
if($count>0){
    echo "<script>alert('Email Already In') </script>"."<script>alert('phone Already In') </script>";
}

else{
    $query =  "INSERT INTO insert_data (name,email,phone,dept)
    VALUES ('$name','$email','$phone','$dept')";
   $insert = mysqli_query( $connect ,$query );

   if($insert){
     echo "<script>alert('data send success')</script>";
   }
   else{
       echo "<script>alert('data send failed')</script>";
   }
}




      
    }
?>`Preformatted text`
0 likes
23 replies
sr57's avatar

Did you start a Laravel app?

1 like
Sinnbeck's avatar

@sr57 pretty sure this has nothing to do with laravel. Just plain php :)

1 like
sultanwebdev's avatar

@sr57 i need both of validation email & phone in my database first check if no data previous then data insert

sr57's avatar
sr57
Best Answer
Level 39

how to both of validation email & phone

You can use OR in your sql

SELECT * FROM insert_data WHERE email = '$email' OR phone='$phone'
Sinnbeck's avatar

I hope this code is just for learning php as I could drop your database very easy using your code as it is now

Sinnbeck's avatar

@sr57 of course :). I meant, I hope this won't be used in production

Sinnbeck's avatar

@sultanwebdev learning php is an excellent idea but laravel is without a doubt the best php framework that exists and there are tons of tutorials

Please or to participate in this conversation.