duanliushua5026 2012-11-24 12:05
浏览 55

注册后验证有问题

I'm doing a registration page. It requires the name, password, email, gender, nationality, date of birth and other things.

I did the registration and it was good. But I need to add the validation and this is what I could do so far:

<?php include("config.php"); ?>
    <!DOCTYPE html>
    <html lang="en">

    <!-- CSS -->
    <link rel="stylesheet" href="css/styles.css" type="text/css"/>
    <link type="text/css" href="css/jquery-ui-1.7.2.custom.css" rel="stylesheet" /> 

    <!-- JavaScript -->
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script>
    <script src="js/validation.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function(){
                    $('#datepicker').datepicker({
                        dateFormat:'dd/mm/yy',
                        changeMonth: true,
                        changeYear: true,
                        yearRange: '-90:+0',
                        maxDate: '+0'
                    });
        });
    </script>
    </head>

    <head>
    <title></title>
    <meta charset="utf-8">
    <link rel="stylesheet" href="css/reset.css" type="text/css" media="all">
    <link rel="stylesheet" href="css/layout.css" type="text/css" media="all">
    <link rel="stylesheet" href="css/style.css" type="text/css" media="all">
    <script type="text/javascript" src="js/jquery-1.4.2.js" ></script>
    <script type="text/javascript" src="js/cufon-yui.js"></script>
    <script type="text/javascript" src="js/cufon-replace.js"></script>
    <script type="text/javascript" src="js/Myriad_Pro_italic_600.font.js"></script>
    <script type="text/javascript" src="js/Myriad_Pro_italic_400.font.js"></script>
    <script type="text/javascript" src="js/Myriad_Pro_400.font.js"></script>
    <!--[if lt IE 9]>
        <script type="text/javascript" src="http://info.template-help.com/files/ie6_warning/ie6_script_other.js"></script>
        <script type="text/javascript" src="js/html5.js"></script>
    <![endif]-->
    <?php $error_messages = array(
        'T1' => 'Please enter a Name to proceed.',
        'T2' => 'Please enter a valid Email Address to continue.',
        'T3' => 'Please enter your Message to continue.'
    ); 
    ?>
    </head>
    <body id="page2">
    <div class="body1">
        <div class="main">
    <!-- header -->
            <header>
                <div class="wrapper">
                    <h1><a href="index.html" id="logo">Air Lines</a><span id="slogan">International Travel</span></h1>
                    <div class="right">
                        <nav>
                            <ul id="top_nav">
                                <li><a href="index.html"><img src="images/img1.gif" alt=""></a></li>
                                <li><a href="index-4.html"><img src="images/img2.gif" alt=""></a></li>
                                <li class="bg_none"><a href="#"><img src="images/img3.gif" alt=""></a></li>





                            </ul>
                        </nav>
                        <nav>
                            <ul id="menu">
    <li><a href="index.php">Home</a></li>
                                <li  id="menu_active" ><a href="LSU.php">Login/sign up</a></li>
                                <li><a href="V&M.php">Vision and mission</a></li>

                                <li><a href="contact.php">Contacts</a></li>
                            </ul>
                        </nav>
                    </div>
                </div>
            </header>
        </div>
    </div>
    <div class="main">
        <div id="banner"></div>
    </div>
    <!-- header -->
    <div class="main">
    <!-- content -->
        <section id="content">
            <article class="col1">
                <div class="pad_1">
                    <h2>Login</h2>
                  <form id="form_1" action="login.php" method="post">

                        <div class="wrapper">
                            User Name:
                            <div class="bg"><input type="text" name="LogIn_Name" class="input input1" value="Enter your name" onblur="if(this.value=='') this.value='Enter your name'" onfocus="if(this.value =='Enter your name' ) this.value=''"></div>
                        </div>
                    <div class="wrapper">
                            Password:
                            <div class="bg"><input type="password" name="LogIn_Pass" class="input input1" value="Enter your password" onblur="if(this.value=='') this.value='Enter your password'" onfocus="if(this.value =='Enter your password' ) this.value=''"></div>
                      </div>
                      <div class="wrapper">

                        <h2 id="coq"> <a href="Forget.php">Forget Password</a></h2>

                          <input type="submit" class="button2" value="GO">
                    </div>
                    </form>



                    <h2>&nbsp;</h2>
                </div>
            </article>
            <article class="col2 pad_left1">
                <h2>Registration</h2>
                <div class="wrapper">
                    <figure class="left marg_right1"></figure>
                    <p> 

                                    <form id="form_1" action="" method="post">
    <div class="wrapperr"  >
    <?php 

    $username =  $_POST["T1"];
    $password =  $_POST["T2"];
    $repassword =  $_POST["T3"];
    $email =  $_POST["T4"];
    $gender =  $_POST["T5"];
    $Cou =  $_POST["T6"];
    $DO=  $_POST["T7"];
    $passport=  $_POST["T8"];
    $phone=  $_POST["T9"];

    {
    if((strlen($username)<3)){
    echo "The username is too short"."</br>";


    if((strlen($gender)<3)){
    echo "Gender"."</br>";
    }


    if((strlen($Cou)<2)){
    echo "The CO too short"."</br>";
    }


    if((strlen($phone)<5)){
    echo "The phone is too short"."</br>";
    }

    if((strlen($password)<5)){
    echo "The password is too short"."</br>";
    }
    }
    else{
    if($password == $repassword){
    $chec = mysql_query("SELECT * FROM register WHERE name='$username'"); 
    if(strlen($chec['name'])>0){
    echo "The username '$username' already exists";
    }
    else{
    $check_variable=stripos($email,"@");
    if($check_variable){

    $password=md5($password);
    mysql_query("INSERT INTO register (name,password,email,gender,country,DOB,phone,passport) VALUES ('$username','$password','$email','$gender','$Cou','$DO','$phone','$passport')");
    echo "Registration Successful .. Click <a href='index.php'> here </a> to home";
    }
    else{
    echo "email is invalid";
    }
    }
    }
    else{
    echo "The password in both field doesn't match.";
    }
    }
    }






    ?>
        </div>              <div class="wrapper">
                            Name:
                            <div class="bg"><input type="text" name="T1" class="input input1"  value="Enter your name" onblur="if(this.value=='') this.value='Enter your name'" onfocus="if(this.value =='Enter your name' ) this.value=''"></div>
                        </div>

                                            <div class="wrapper">
                            Password:
                            <div class="bg"><input type="password" name="T2"  class="input input1" value="Enter the password" onblur="if(this.value=='') this.value='Enter the password'" onfocus="if(this.value =='Enter the password' ) this.value=''"></div>
                        </div>


                                            <div class="wrapper">
                            Confirm password:
                            <div class="bg"><input type="password" name="T3" class="input input1" value="Confirm the password" onblur="if(this.value=='') this.value='Confirm the password'" onfocus="if(this.value =='Confirm the password' ) this.value=''"></div>
                        </div>

                                            <div class="wrapper">
                            e-mail:
                            <div class="bg"><input type="text" name = "T4" class="input input1" value="Enter your e-mail" onblur="if(this.value=='') this.value='Enter your e-mail'" onfocus="if(this.value =='Enter your e-mail' ) this.value=''"></div>
                        </div>


                        <div class="wrapper">
                            Gender:
                            <div class="bg">
                              <td>
                              <input type="radio" name="T5" value="Male">
                              Male
                              </td><td>
                               <input type="radio" name="T5" value="Female">
                              Female</td>


                          </div>
                        </div>


                                    <div class="wrapper">
                            NATIONALITY:
                              <div class="bg"><input type="text" name="T6" class="input input1" value="Enter your country" onblur="if(this.value=='') this.value='Enter your country'" onfocus="if(this.value =='Enter your country' ) this.value=''"></div>
                        </div>


                        <div class="wrapper">

                                                        <div class="wrapper">
                            Passport number:
                              <div class="bg"><input type="text" name="T8" class="input input1" value="Enter your passport number" onblur="if(this.value=='') this.value='Enter your passport number'" onfocus="if(this.value =='Enter your passport number' ) this.value=''"></div>
                        </div>


                        <div class="wrapper">


                            Date of birth:
                      <div class="wrapper">
                                <div class="bg left"><input type="text" name="T7" class="input input2" value="mm/dd/yyyy " onblur="if(this.value=='') this.value='mm/dd/yyyy '" onfocus="if(this.value =='mm/dd/yyyy ' ) this.value=''" id="datepicker"  >
                                  <br/><span id="bdayInfo"></span>

                        </div>
                                <div class="bg right"></div>
                            </div>
                        </div>
                        Phone number:
                                                <div class="wrapper">
                                <div class="bg left"><input type="text" name="T9" class="input input2" value="" onblur="if(this.value=='') this.value=''" onfocus="if(this.value =='' ) this.value=''"></div>
                                <div class="bg right"></div>
                          </div>
                        </div>
                        <div class="wrapper">
                        <p>&nbsp;</p>
                      <input type="submit" class="button2" name="Go" value="GO">
                        </div>
                    </form>

                    </p>
                </div>
                <p>&nbsp;</p>
              <h2>&nbsp;</h2>
            </article>
        </section>
    <!-- / content -->
    </div>
    <div class="body2">
        <div class="main">
    <!--footer -->
            <footer>
                Website template designed by <a href="http://www.templatemonster.com/" target="_blank" rel="nofollow">www.templatemonster.com</a><br>
                3D Models provided by <a href="http://www.templates.com/product/3d-models/" target="_blank" rel="nofollow">www.templates.com</a>
            </footer>
    <!-- / footer -->
        </div>
    </div>
    <script type="text/javascript"> Cufon.now(); </script>
    </body>
    </html>
  • 写回答

2条回答 默认 最新

  • dongshui9690 2012-11-24 13:16
    关注

    HTML 5 has a bunch of built in validation tools and you could use jQuery or Javascript to further enhance that. I am not a big fan of validating variables on a new page, especially when we could prevent the page load completely. Definitely look into some sort of Client Side validation instead of posting to the the PHP page.

    W3Schools has a decent article on Javascript validation: http://www.w3schools.com/js/js_form_validation.asp

    The jQuery link was already given in a comment above.

    If Javascript is not your specialty then try something like this. It is prebuilt and has some nice features. Best of all it is free. http://www.javascript-coder.com/html-form/javascript-form-validation.phtml

    评论

报告相同问题?

悬赏问题

  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件