1

i'm looking for a way to return message in my form if the email submited is already existed. i want the 4th if to be executed

    $conn = new PDO("mysql:host=localhost;dbname=ali","root","");
    $sql = "insert into admin(id,email,password,repeatpass) values(null,?,?,?)";
    $result = $conn->prepare($sql);
    $result ->bindValue(1,$_POST["email"]);
    $result ->bindValue(2,$_POST["pass"]);
    $result ->bindValue(3,$_POST["repeat"]);
    $number = $result->rowCount();



    if (empty($_POST["email"]) or empty($_POST["pass"]) or empty($_POST["repeat"])){
        echo "fill all the blanks";
    }
    else if(strlen($_POST["pass"]) < 6){
        echo "password should not be less than 6 characters!";
    }
    else if($_POST["pass"] !== $_POST["repeat"]){
        echo "passwords not matched";
    }
    else if($number > 0){
        echo "is already exist";
    }
    else{

        $result->execute();
        echo "successfuly registered";
    }
ArSeN
  • 5,133
  • 3
  • 19
  • 26
ali parsi
  • 41
  • 2
  • By "the 4th to be executed" you mean you want to run into the case where it says "is already exist"? Sounds like you have to do a query and check if the entry exists before just inserting int blindly – ArSeN Jan 17 '20 at 20:08
  • See https://stackoverflow.com/a/58942841/1839439 – Dharman Jan 17 '20 at 20:45
  • You are inserting data before doing those verifications! – Triby Jan 17 '20 at 21:46

0 Answers0