How to stop form submission if email address is already available in MySQL db ? : <p>I have coded the following form with PHP &amp; MySQL as database. I want to prevent the form from submitting data, if email address already exists in database. I also want to disable the submit button, if email exists in database. </p>

<h2>Index.php:</h2>

<pre><code>    &lt;?php
    require_once './include/user.php';
    $user_obj = new user();

    if (isset($_POST['submit'])) {
        $message = $user_obj-&gt;save_user($_POST);
    }
    ?&gt;


    &lt;!DOCTYPE html&gt;

    &lt;html&gt;
        &lt;head&gt;
            &lt;title&gt;PHP Form With JS Validation&lt;/title&gt;
            &lt;meta charset="UTF-8"&gt;
            &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
            &lt;link rel="stylesheet" type="text/css" href="css/style.css"&gt;
            &lt;script type="text/javascript" src="js/country.js"&gt;&lt;/script&gt;
            &lt;script type="text/javascript" src="js/jsval.js"&gt;&lt;/script&gt;
        &lt;/head&gt;
        &lt;body&gt;
            &lt;p&gt;PHP Form With JS Validation&lt;/p&gt;

            &lt;div id="id1"&gt;
                &lt;form id="myForm" name="myForm" action="index.php" method="POST" onsubmit="return validateStandard(this)"&gt;
                    &lt;table&gt;

                        &lt;tr&gt;&lt;td&gt;&lt;input type="text" name="name" value="" placeholder="name" required="required" regexp="JSVAL_RX_ALPHA"&gt;&lt;/td&gt;&lt;/tr&gt;
                        &lt;tr&gt;&lt;td&gt;&lt;input type="email" name="email" value="" placeholder="email" required="required" required regexp="JSVAL_RX_EMAIL"&gt;&lt;/td&gt;&lt;/tr&gt;
                        &lt;tr&gt;&lt;td&gt;&lt;input type="password" name="user_password" value="" placeholder="password" required="required"&gt;&lt;/td&gt;&lt;/tr&gt;
                        &lt;tr&gt;&lt;td&gt;&lt;input type="tel" name="phone" value="" placeholder="phone no" required="required"&gt;&lt;/td&gt;&lt;/tr&gt;

                        &lt;tr&gt;
                            &lt;td&gt;
                                &lt;input type="radio" name="gender" value="male" checked&gt;Male
                                &lt;input type="radio" name="gender" value="female"&gt;Female
                            &lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;&lt;td&gt;&lt;textarea name="address" placeholder="address" required="required"&gt;&lt;/textarea&gt;&lt;/td&gt;&lt;/tr&gt;
                        &lt;tr&gt;&lt;td&gt;&lt;input type="text" name="city" value="" placeholder="city" required regexp="JSVAL_RX_ALPHA"&gt;&lt;/td&gt;&lt;/tr&gt;
                        &lt;tr&gt;&lt;td&gt;
                                &lt;select name="country" required="required" exclude=" "&gt;
                                    &lt;option value=" "&gt;Please Select Country&lt;/option&gt;
                                    &lt;script type="text/javascript"&gt;printCountryOptions();&lt;/script&gt;
                                &lt;/select&gt;
                            &lt;/td&gt;&lt;/tr&gt;
                        &lt;tr&gt;&lt;td&gt;&lt;input type="text" name="zipcode" value="" placeholder="zipcode" required="required" regexp="JSVAL_RX_ALPHA_NUMERIC"&gt;&lt;/td&gt;&lt;/tr&gt;

                        &lt;tr&gt;&lt;td&gt;&lt;input type="checkbox" name="agree" value="on" required="required"&gt; I agreed with all the terms!&lt;/td&gt;&lt;/tr&gt;
                        &lt;tr&gt;&lt;td&gt;&lt;input type="submit" id="sbtn" name="submit" value="Register"&gt;&lt;/td&gt;&lt;/tr&gt;


                    &lt;/table&gt;
                &lt;/form&gt;
            &lt;/div&gt;
        &lt;/body&gt;
    &lt;/html&gt;
    &lt;script&gt;
        document.forms['myForm'].reset();
    &lt;/script&gt;
</code></pre>

<h2>db: user.php</h2>

<pre><code>    &lt;?php

    class user {

        public function save_user($data) {
            $hostname = "localhost";
            $username = "root";
            $password = "";
            $dbname = "db_user_info";

            $conn = mysqli_connect($hostname, $username, $password, $dbname);
            $user_password = md5($data['user_password']);
            $sql = "INSERT INTO tbl_user (name, email, user_password, phone, gender, address, city, country, zipcode, agree) VALUES ('$data[name]','$data[email]','$user_password', '$data[phone]','$data[gender]','$data[address]','$data[city]','$data[country]','$data[zipcode]','$data[agree]')";
            if (!mysqli_query($conn, $sql)) {
                die('Sql Error:' . mysqli_error($conn));
            } else {           
                header('Location:thanks.php');
            }
            mysqli_close($conn);
        }



    }
</code></pre>
