在没有jQuery

时间:2016-05-21 00:47:46

标签: php

我是php的初学者,我想知道是否有可能在不使用jQuery的情况下进行用户名可用性检查,我的意思是纯php / html?我尝试使用$ _POST ['用户名'] = $用户名或使用$ _SESSION ['用户名'] = $用户名然后$ _POST ['用户名&# 39;] = $ _ SESSION ['用户名']保持用户名输入框中的用户名不被删除(在点击“检查用户名”按钮后)并且失败。我知道这对我来说可能听起来很愚蠢,但也许还有另外一种方式吗?这是第一个代码:

    <!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>New Member</title>
    </head>

    <body>
        <center>
            <h3>@------------ Create New Account ------------@</h3>
            <form method="post" name="form1">
                <table width="299" border="0">
                  <tbody>
                    <tr>
                      <td width="62">Username</td>
                      <center><td>:<br></td></center>
                      <td colspan="2"><input type="text" name="username">
                      <input type="submit" name="check" value="Check">

                      <?php
                        include('connection.php');
                        if(isset($_POST['check']))
                        {
                            $userchk=$_POST['username'];
                            $query="select username from login where username='$userchk'";
                            $check=mysqli_query($connection,$query);
                            if(mysqli_num_rows($check)==1)
                            {
                                echo "Username already in used";
                            }
                            else
                            {
                                $_POST['username']=$userchk;
                                echo "Username available";
                            }
                        }
                        ?></td>
                    </tr>
                   </tbody>
                 </table>
             </form>
             <form method="post" name="form2" action="signup_process.php">
                <table>
                    <tbody>
                    <tr>
                      <td height="66">Email</td>
                      <center><td>:</td></center>
                      <td colspan="2"><input type="text" name="email"></td>
                    </tr>
                    <tr>
                        <td height="74">Sites</td>
                      <center><td>:</td></center>
                        <td colspan="2"><input type="text" name="sites"></td>
                    </tr>
                    <tr>
                        <td>Password</td>
                        <center><td>:</td></center>
                        <td colspan="2"><input type="text" name="password"></td>
                    </tr>
                    <tr>
                      <td></td>
                      <center>
                      <td width="6">&nbsp;</td>
                      <td width="72"><input type="submit" name="submit" value="Submit"></td>
                      <td width="115"><input type="reset" name="reset" value="Reset"></td>                                    
                      <td width="22">&nbsp;</td>
                      </center>
                    </tr>
                </tbody>
              </table>
        </form>
        </center>
    </body>
</html>

第二个代码:

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>New Member</title>
    </head>

    <body>
        <center>
            <h3>@------------ Create New Account ------------@</h3>
            <form method="post" name="form1">
                <table width="299" border="0">
                  <tbody>
                    <tr>
                      <td width="62">Username</td>
                      <center><td>:<br></td></center>
                      <td colspan="2"><input type="text" name="username">
                      <input type="submit" name="check" value="Check">

                      <?php
                        include('connection.php');
                        if(isset($_POST['check']))
                        {
                            $userchk=$_POST['username'];
                            $query="select username from login where username='$userchk'";
                            $check=mysqli_query($connection,$query);
                            if(mysqli_num_rows($check)==1)
                            {
                                echo "Username already in used.";
                            }
                            else
                            {
                                session_start();
                                $_SESSION['username']=$userchk;
                                $_POST['username']=$_SESSION['username'];
                                echo "Username available.";
                            }
                        }
                        ?></td>
                    </tr>
                   </tbody>
                 </table>
             </form>
             <form method="post" name="form2" action="signup_process.php">
                <table>
                    <tbody>
                    <tr>
                      <td height="66">Email</td>
                      <center><td>:</td></center>
                      <td colspan="2"><input type="text" name="email"></td>
                    </tr>
                    <tr>
                        <td height="74">Sites</td>
                      <center><td>:</td></center>
                        <td colspan="2"><input type="text" name="sites"></td>
                    </tr>
                    <tr>
                        <td>Password</td>
                        <center><td>:</td></center>
                        <td colspan="2"><input type="text" name="password"></td>
                    </tr>
                    <tr>
                      <td></td>
                      <center>
                      <td width="6">&nbsp;</td>
                      <td width="72"><input type="submit" name="submit" value="Submit"></td>
                      <td width="115"><input type="reset" name="reset" value="Reset"></td>                                    
                      <td width="22">&nbsp;</td>
                      </center>
                    </tr>
                </tbody>
              </table>
        </form>
        </center>
    </body>
</html>

谢谢。

0 个答案:

没有答案