How to Prevent Multiple and Duplicate Form Submission Using PHP and MySQL

0

In this tutorial we will show you how to prevent multiple and duplicate form submission using PHP and MySQL. Below you will find two simple tricks for preventing duplicate submissions, you can use either of these or a combination of both. You may also like How to Check UserName and Email Availability From Database using PHP and Ajax.

HTML Code

<html>
    <body>
        <form action="" method="post">
            <input type="text" name="email" placeholder="Enter Email"/>
            <input type="password" name="password" placeholder="********"/>
            <input type="submit" name="submit_data" value="SUBMIT"/>
        </form>
    </body>
</html>

PHP Code

<?php
if (isset($_POST['submit_data'])) {
    $email = $_POST['email'];
    $pass = $_POST['password'];

    $get_user = mysqli_query($con,"select * from user where email='$email' and password='$pass'");
    if (mysqli_num_rows($get_user) > 0) {
        echo "Already Submitted";
    } else {
        mysqli_query($con,"insert into user (email,password) values($email','$pass')");
        echo "done";
    }
}
?>