PHP不发布我的表单值

时间:2017-01-08 16:30:50

标签: php

我现在已经摸不着头脑了一个小时,无法弄清楚为什么php不会发布我的表格值。

代码

        <!-- Login -->
        <div class="login__block toggled" id="l-login">
            <div class="login__block__header">
                <i class="zmdi zmdi-account-circle"></i>
                Hi there! Please Sign in

                <div class="actions login__block__actions">
                    <div class="dropdown">
                        <a href="#" data-toggle="dropdown"><i class="zmdi zmdi-more-vert"></i></a>

                        <ul class="dropdown-menu pull-right">
                            <li><a data-block="#l-register" href="#">Create an account</a></li>
                            <li><a data-block="#l-forget-password" href="#">Forgot password?</a></li>
                        </ul>
                    </div>
                </div>
            </div>

            <div class="login__block__body">
                <div class="form-group form-group--float form-group--centered form-group--centered">
                    <input type="text" class="form-control" name="email">
                    <label>Email Address</label>
                    <i class="form-group__bar"></i>
                </div>

                <div class="form-group form-group--float form-group--centered form-group--centered">
                    <input type="password" class="form-control" name="password">
                    <label>Password</label>
                    <i class="form-group__bar"></i>
                </div>

                <button type="submit" class="btn btn--light btn--icon m-t-15"><i class="zmdi zmdi-long-arrow-right"></i></button>
            </div>
            <?php
            if(isset($_POST['login'])) {
                if(isset($_POST['email']) && isset($_POST['password']) &&
                is_string($_POST['email']) && is_string($_POST['password']) &&
                !empty($_POST['email']) && !empty($_POST['password'])) {
                    $email = stripslashes(strip_tags($_POST['email']));
                    $password = md5($_POST['password']);

                    $stmt = $pdo->prepare('SELECT * FROM users WHERE UserEmail = :UserEmail');
                    $stmt->bindParam(':UserEmail', $email);
                    $stmt->execute();

                    if($stmt->rowCount() > 0) {
                        $stmt = $pdo->prepare('SELECT * FROM users WHERE UserEmail = :UserEmail AND UserPassword = :UserPassword');
                        $stmt->execute(array(':UserEmail' => $email, ':UserPassword' => $password));

                        if($stmt->rowCount() > 0) {
                            $row = $stmt->fetch();
                            $UserLevel = $row['UserLevel'];

                            if($UserLevel == 'banned') {
                                $display->ReturnError('Your account has been suspended.');
                                return false;
                            }
                            $UserID = $row['UserID'];
                            $time = time();
                            $IPAddress = $_SERVER['REMOTE_ADDR'];

                            $_SESSION['auth'] = $UserID;

                            $stmt = $pdo->prepare('INSERT INTO logs (LogUserID, LogDate, LogIPAddress) VALUES (:LogUserID, :LogDate, :LogIPAddress)');
                            $stmt->execute(array(':LogUserID' => $UserID, ':LogDate' => $time, ':LogIPAddress' => $IPAddress));

                            $display->ReturnSuccess('You was successfully logged in.');
                            $settings->forceRedirect('index.php', 2);
                        } else {
                            $display->ReturnError('Invalid user credentials.');
                        }
                    } else {
                        $display->ReturnError('User with these credentials does not exists.');
                    }
                }
            }
        ?>
        </div>

请注意,我对PHP非常陌生,如果你可以帮助我的话,这对我来说意味着世界!谢谢。

3 个答案:

答案 0 :(得分:1)

提交按钮仅在表单标记内部有效。 您的代码没有任何表单标记 试试这个

  <form action="" >
        <!-- Login -->
        <!--your code here -->
  </form>

答案 1 :(得分:0)

添加像这样的表单属性

<div class="login__block__body"> 
  <form action="url which will process form" method="POST">
                <div class="form-group form-group--float form-group--centered form-group--centered">
                    <input type="text" class="form-control" name="email">
                    <label>Email Address</label>
                    <i class="form-group__bar"></i>
                </div>

                <div class="form-group form-group--float form-group--centered form-group--centered">
                    <input type="password" class="form-control" name="password">
                    <label>Password</label>
                    <i class="form-group__bar"></i>
                </div>

                <button type="submit" class="btn btn--light btn--icon m-t-15"><i class="zmdi zmdi-long-arrow-right"></i></button>
     </form>

            </div>

答案 2 :(得分:0)

所有<input>代码必须在<form>代码中。

<form action="" method="post"> //Submits form to same page
<input/>
<input/>
<button type="submit" class="btn btn--light btn--icon m-t-15"><i class="zmdi zmdi-long-arrow-right"></i></button>
</form>

当您“提交”此表单时,它将POST表单中的所有输入值,您从$_POST['name_of_input']变量中检索

我建议在PHP之前学习HTML。