未定义的索引错误,正确编程

时间:2015-03-26 20:28:41

标签: php html mysql forms

和很多人一样,我收到了错误: "注意:未定义的索引:第8行"

中的... \ login.php中的电子邮件

第8行:

$email = $_POST['email'];

我们收到了电子邮件'从这种形式:(index.html)

<!DOCTYPE html>
<html>
<head>
    <title>Login</title>
 </head>

<body>
<form method="post" action="login.php">
E-mail: <input type="text" name="email">
Password: <input type="password" name="password">
<input type="submit" name="submit" value="submit">
</form>

Don't have an account? Create <a href="create.html">here</a>.
</body>
</html>

Login.php看起来像这样:

<?php
    require_once("db.php");
    require_once("functions.php");

    if(isset($_POST['submit'])) {
        global $connection; 

        $email = $_POST['email'];
        $safe_email = mysqli_real_escape_string($connection, $email);

        $password = $_POST['password'];

        $query = "SELECT * FROM users WHERE email = '{$safe_email}'";
        $result = mysqli_query($connection, $query);
        if($row = mysqli_fetch_array($result)) {
            $set_password = $row['password'];
            $input_password = crypt($password, $set_password);

            if($input_password == $set_password) {
                echo "winnar";
            } else {
                echo "wrong password";
            }
        } else {
            echo "we didn't recognise this email in our database";
        }
    }
?>

我检查了拼写,结束标签,结尾代码中的错误,搜索了一些Stackoverflow问题,但似乎没有任何帮助。好像电子邮件从未发布过,但它应该是。

0 个答案:

没有答案