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

In this tutorial, we will show you how to prevent multiple and duplicate form submissions 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.

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";
    }
}
?>

Leave a Reply

Your email address will not be published. Required fields are marked *