如何检查用户之前是否输入了他的数据

时间:2015-05-13 12:25:25

标签: php mysql forms

我正在研究这个php,mysql和如果用户在注册页面中输入了一些信息并且存储在数据库中的信息,如果用户再次再次输入相同的信息我应该如何在发送信息之前检查一下又到了db?

我正在使用localhost作为我的服务器。

<?php
session_start();
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "hotelsava";
$dberror1 = " Could not connect to the database ! ";
$connect = mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
if(mysqli_connect_errno($connect))
{
    echo mysqli_connect_error();

}
else
{
    echo 'DB Connected';
}
if(isset($_POST['submit']))
{ 

    $fname = $_POST['fname'];

    $faname = $_POST['faname'];

    $em = $_POST['em'];

    $em2 = $_POST['em2'];

    $Uaname = $_POST['Uaname'];

    $pwd1 = $_POST['pwd1'];

    $pwd2 = $_POST['pwd2'];

    $cardt = $_POST['cardt'];

    $cardnum = $_POST['cardnum'];

    $cardco = $_POST['cardco'];

    $namecard = $_POST['namecard'];




    $query = "INSERT INTO signuptable (fname,faname,em,em2,Uaname,pwd1,pwd2,cardt,cardnum,cardco,namecard)VALUES ('$fname','$faname', '$em', '$em2','$Uaname','$pwd1', '$pwd2', '$cardt', ' $cardnum','$cardco', '$namecard')";


    $result=mysqli_query($connect,$query);

    if($result==1)
    {
        echo ' sucessful';
        $status="done";
    }
    else 
    {
        echo ' failed';
         $status="notdone";
    }



    }

?>


<html>
    <head>
         <link rel="stylesheet" href="hotelprojectstyle.css">
         <title>Sign Up</title>
         <meta charset="UTF-8">
         <meta name="viewport" content="width=device-width">
   </head>
   <body>
        <?php
            include 'Header.php';
        ?>

        <h2 id="signup">Sign Up</h2>
        <?php if(isset($_GET['status']) && $_GET['status']==="done") { ?>
        <p> successfully register</p>  
        <?php header("Location: Homepage.php?status=$status"); ?>
        <?php } else {if(isset($_GET['status']) && $_GET['status']==="notdone") { ?>
             <p>Sorry the registration has been failed</p>
             <?php } else { ?>
         <form name="signupform" action="SignUpPage.php" method="POST" onsubmit="return signuptable();" enctype="multipart/form-data">
             <table>
                 <tbody>
                     <tr><td><b>Personal Information</b></td></tr>
                     <tr>

                         <td><label for="fname"> First Name </label></td>
                         <td><input type="text" name="fname" id="fname"><span class="error"> * </span></td>

                    </tr>
                    <tr>
                        <td><label for="faname"> Family Name </label></td>
                        <td> <input type="text" name="faname" id="faname" </td>
                    </tr>
                    <tr>
                        <td> <label for="em">Email</label></td>
                        <td> <input type="email" name="em" id="em"><span class="error"> * </span></td>
                        <td> <label for="em2">Repeat Email</label></td>
                        <td> <input type="email" name="em2" id="em2"><span class="error"> * </span></td>
                    </tr>
                    <tr>
                        <td><label for="gender"> Gender</label></td>
                        <td><input type="radio" name="gender" value="male" checked="">Male</td>
                        <td><input type="radio" name="gender" value="female" checked="">female</td>

                   </tr>

                   <tr><td><b>Log-in Information</b></td></tr>
                   <tr>
                       <td> <label for="Uaname"> Username </label></td>
                       <td> <input type="text" name="Uaname" id="Uaname"><span class="error"> * </span></td>
                   </tr>

                   <tr>
                       <td><label for="pwd1">Password</label></td>
                       <td><input type="Password" name="pwd1" id="pwd1"><span class="error"> * </span></td>

                       <td>  <label for="pwd2">Repeat Password</label></td>
                       <td><input type="Password" name="pwd2" id="pwd2"><span class="error"> * </span></td>

                   </tr>
                   <tr><td><b>Payment Information</b></td></tr>

                   <tr>
                       <td><label for="cardt">Card Type</label></td>
                       <td><input type="text" name="cardt" id="cardt"><span class="error"> * </span></td> 


                       <td><label for="cardnum">Card Number</label></td>
                       <td><input type="text" name="cardnum" id="cardnum"><span class="error"> * </span></td>
                  </tr>
                  <tr>
                       <td><label for="cardco">Card Code</label></td>
                       <td><input type="text" name="cardco" id="cardco"><span class="error"> * </span></td>

                       <td><label for="namecard">Name on Card</label></td>
                       <td><input type="text" name="namecard" id="namecard"><span class="error"> * </span></td>
                 </tr>

                 <tr><td id="colo">*  Required Field</td></tr>
                 <tr>
                     <td><input type="submit" name="submit" id="submit" value="Sign Up" onclick="validate()"></td> 
                 </tr>


          </tbody>
  </table>
</form>
         <?php } } ?>

        <script type="text/javascript">
        function validate()
        {
                var spans = document.getElementsByTagName("span");

                var namee = document.signupform.fname.value;
                if(namee==="")
                {
                  spans[0].style.visibility="visible";
                  document.getElementById("h").style.background="pink";
                }
                var em1 = document.signupform.Em.value;
                if(em1==="")
                {
                  spans[1].style.visibility="visible";
                  document.getElementById("i").style.background="pink";
                }
                var em22 = document.signupform.em2.value;
                if(em22==="")
                {
                  spans[2].style.visibility="visible";
                  document.getElementById("j").style.background="pink";
                }
                var unamee = document.signupform.Uaname.value;
                if(unamee==="")
                {
                  spans[3].style.visibility="visible";
                  document.getElementById("k").style.background="pink";
                }
                var pwaa1 = document.signupform.pwd.value;
                if(pwaa1==="")
                {
                  spans[4].style.visibility="visible";
                  document.getElementById("p1").style.background="pink";
                }
                var pwaa2 = document.signupform.pwd2.value;
                if(pwaa2==="")
                {
                  spans[5].style.visibility="visible";
                  document.getElementById("p2").style.background="pink";
                }
                var cardtt = document.signupform.cardt.value;
                if(cardtt==="")
                {
                  spans[6].style.visibility="visible";
                  document.getElementById("l").style.background="pink";
                }
                var cardnuum= document.signupform.cardnum.value;
                if(cardnuum==="")
                {
                  spans[7].style.visibility="visible";
                  document.getElementById("m").style.background="pink";
                }
                var cardcoo = document.signupform.cardco.value;
                if(cardcoo==="")
                {
                  spans[8].style.visibility="visible";
                  document.getElementById("n").style.background="pink";
                }
                var namecardd1 = document.signupform.namecard.value;
                if(namecardd1==="")
                {
                  spans[9].style.visibility="visible";
                  document.getElementById("oo").style.background="pink";
                }


            }
      </script>





    <?php
    include ('Footer.php');
    ?>
</body>

1 个答案:

答案 0 :(得分:0)

您可以通过匹配每个用户的电子邮件ID 进行检查。如果数据库中已存在具有该电子邮件ID的用户,则可以通过显示某些特定消息来跳过此用户。