PHP表单刷新

时间:2015-06-12 16:13:13

标签: php mysql html5 twitter-bootstrap-3

好的,这是代码!我正在开发phpstorm 问题是每次我点击提交页面刷新但不重定向或执行带变量的回声!

有人可以指出任何错误吗?

require_once "db.php";

$html = <<<TAG

<!DOCTYPE html>
<html>
<head>
<title>Log In</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<style>
html, body, .container {
    height: 100%;
}
.container {
    display: table;
    vertical-align: middle;
}
.vertical-center-row {
    display: table-cell;
    vertical-align: middle;
}
</style>

</head>

<body>

<div class="container">
    <div class="row vertical-center-row">
        <div class="col-lg-12">
            <div class="row">
                <div class="col-xs-4 col-xs-offset-4">
                <h3>Sign In</h3>
                <br>
                    <form action="login.php" method="post" role="form">
                    <div class="form-group">
                    <label for="name"> Name: </label>
                    <input class="form-control" name="name" value="Username" type="text" id="name">
                    </div>
                    <div class="form-group">
                    <label for="password"> Password:</label>
                    <input class="form-control" name="password" value="Password" type="password" id="password">
                    </div>
                    <button type="submit" class="btn btn-primary">Submit</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>


</body>


</html>
TAG;

echo $html;



if(isset($_POST['submit'])){

    $escapedName = mysqli_real_escape_string($_POST['name']);
    $escapedPW = mysqli_real_escape_string($_POST['password']);

    $testPW = hash('sha1', $escapedPW);

    echo $escapedName . $escapedPW;

    $sql = "select * from users where name ='$escapedName' and password='$testPW'";

    if($conn->query($sql)){

        header('location: /user.php');

    }

}
else{

    echo "se di ca ka";

}

1 个答案:

答案 0 :(得分:1)

您正在检查是否设置了提交名称的POST变量,但您没有设置它。您的表单中没有任何名为submit的内容,只有一个未命名的提交按钮。你需要添加name =&#34;提交&#34;到你的提交按钮。

改变这个:

<button type="submit" class="btn btn-primary">Submit</button>

有了这个:

<button type="submit" name="submit" class="btn btn-primary">Submit</button>