我无法执行此PHP代码(HTML)

时间:2015-05-25 08:10:02

标签: php html

所以我在不久前使用过它,但是现在我用它来使用一些不同的代码(Extras)。当我点击“登录”按钮时,我似乎无法运行PHP代码。

任何人都有任何想法出错的地方?

<?php
    require('process.php'); //Remember $username and $password taken as variables
    $ok = 0; //Assume nothing is ok, collect evidence to prove otherwise

    if(isset($_POST["submit"])) {
        //Submit clicked, user possibly logged in - check
        $who = $_POST['nick'];
        $pw = $_POST['pass'];
        $verify = 'select * from users where user ="' . $who . '"';

        $answertable = mysql_query($verify, $connection);
        if (!$answertable) {
            echo 'Invalid username or password';
        } else {
            list($usr, $pwd) = mysql_fetch_row($answertable);
            if (MD5($pw) == $pwd) {
                $ok = 1; //Valid user and password, It's A OK

                echo 'Welcome ' . $usr;
                //Do stuff here because you are a valid user
                echo '<br><a href = "login.php">Logout</a>';

                } else {
                    echo 'Invalid username or password, please try again<br><br>';
                }
            }
     }

     if (!$ok) { //Either login was wrong or not yet tried
       ?>      <!-- Present from to gather login details -->
         <div id="dialog" style="width: 350px; background-color: #FFFFFF; margin: 50px auto; border-radius: 15px; padding: 5px 15px 5px 15px;">
             <form role="form">
                 <div class="form-group">
                     <h2><center>Webmaster login</center></h2>
                 </div>
                 <div class="form-group">
                     <p>Enter your username:</p>
                     <input id="nick" class="form-control" placeholder="Username"/>
                </div>
                <div class="form-group">
                    <p>Enter your password:</p>
                    <input id="pass" class="form-control" type="password" placeholder="Password"/>
                </div>
            </form>
            <hr/>
            <div class="form-group">
                <form method="post" action="index.php">
                    <button type="submit" id="loginbtn" class="btn btn-play btn-primary">Login</button>
                </form>
            </div>
            <br clear="both"/>
            <hr/>
         </div>
         <?php
         }
         ?>

Process.php

<?php
/* Set the connections to the database */
$host = 'localhost';
$username = 'root';
$password = '';
$dbname = 'login';

/* Build a bridge to the server */
$connection = mysql_connect($host, $username, $password) or die('Problems connecting');

/* Connect to the database through the bridge */
mysql_select_db($dbname) or die('Problems finding the database');

?>

1 个答案:

答案 0 :(得分:0)

只使用一种表格 -

     <div id="dialog" style="width: 350px; background-color: #FFFFFF; margin: 50px auto; border-radius: 15px; padding: 5px 15px 5px 15px;">
         <form role="form">
             <div class="form-group">
                 <h2><center>Webmaster login</center></h2>
             </div>
             <div class="form-group">
                 <p>Enter your username:</p>
                 <input id="nick" class="form-control" placeholder="Username"/>
            </div>
            <div class="form-group">
                <p>Enter your password:</p>
                <input id="pass" class="form-control" type="password" placeholder="Password"/>
            </div>
        <hr/>
        <div class="form-group">
                <button type="submit" id="loginbtn" class="btn btn-play btn-primary">Login</button>
        </div>
        <br clear="both"/>
        <hr/>
        </form>
     </div>

将名称添加到提交按钮 -

<button type="submit" id="loginbtn" class="btn btn-play btn-primary" name="submit">Login</button>