简体   繁体   English

我究竟做错了什么? 预备账单登录

[英]What am I doing wrong? Prepared statement login

This is my login.php files, when the form directs to this page to run the code, the screen says 这是我的login.php文件,当形式引导到这个页面运行代码,屏幕说:

"this page is not working" “此页面无法正常工作”

What am I doing wrong and how can I fix it? 我在做什么错,我该如何解决? Also, when I have got the code to work, the cookies have not been set, which makes me think that the error is around there. 另外,当我使代码可用时,尚未设置cookie,这使我认为错误就在附近。

//IF REMEMBER ME IS TURNED ON
$stmt = $conn->prepare("SELECT * FROM users WHERE email=? AND password=?");
$stmt->bind_param("ss", $SearchEmail, $SearchPassword);

// set parameters and execute
$SearchEmail = $email;
$SearchPassword = $password;
$stmt->execute();
if($stmt->fetch() == true) {
    $result = $stmt->get_result();
    while($row = $result->fetch_assoc()) {
        setcookie("SIT_name", $row['FirstName'], time()+3600*24*365*10, '/');
        setcookie("SIT_acc_type", $row['acc_type'], time()+3600*24*365*10, '/');
    }

    $stmt = $conn->prepare("UPDATE users SET last_log=? WHERE email=? AND password=?");
    $stmt->bind_param("sss", $time, $SearchEmail, $SearchPassword);
    $time = 'Time: '.date("h:i:sa").', Date: '.date("d/m/Y").'.';
    $SearchEmail = $email;
    $SearchPassword = $password;
    if ($stmt->execute()) {
        echo "Success";
        //Header('Location: ../');
    }
} else {
    echo "Wrong Username or Password!";
}

Screenshot (from comment section) 屏幕截图 (来自评论部分) 在此处输入图片说明

Try this 尝试这个

//IF REMEMBER ME IS TURNED ON
$stmt = $conn->prepare("SELECT * FROM users WHERE email=? AND password=?");
$stmt->bind_param("ss", $SearchEmail, $SearchPassword);

// set parameters and execute
$SearchEmail = $email;
$SearchPassword = $password;
$stmt->execute();

if($stmt->fetch() == true) {
    $result = $stmt->get_result();
    while ($row = $result->fetch_array()) {
        setcookie("SIT_name", $row['FirstName'], time()+3600*24*365*10, '/');
        setcookie("SIT_acc_type", $row['acc_type'], time()+3600*24*365*10, '/');
    }

    $stmt = $conn->prepare("UPDATE users SET last_log=? WHERE email=? AND password=?");
    $stmt->bind_param("sss", $time, $SearchEmail, $SearchPassword);
    $time = 'Time: '.date("h:i:sa").', Date: '.date("d/m/Y").'.';
    $SearchEmail = $email;
    $SearchPassword = $password;
    if ($stmt->execute()) {
        echo "Success";
        //Header('Location: ../');
    }
} else {
    echo "Wrong Username or Password!";
}

After many hours of messing around with the code, I have figured out a fix, it's not the best but it'll do as I don't have time (I'm 16 and currently doing my GCSEs). 经过数小时的代码弄乱后,我想出了一个解决办法,虽然它不是最好的,但由于我没有时间(我16岁,目前正在做我的GCSE),所以可以解决。 The working code is as follows: 工作代码如下:

//IF REMEMBER ME IS TURNED ON
$stmt = $conn->prepare("SELECT FirstName, acc_type FROM users WHERE email=? AND password=?");
$stmt->bind_param("ss", $email, $password);

// set parameters and execute
$email = $OrigEmail;
$password = $OrigPassword;

$stmt->execute();
$stmt->bind_result($FirstName, $acc_type);
$stmt->store_result();

if ($stmt->num_rows == 0) 
{
    Header('Location: ../?err=1');

    $stmt->close();

    return 0;
}
else
{
    $FirstNames = array();
    $acc_types = array();

    while($stmt->fetch())
    {
        $FirstNames[] = $FirstName;
        $acc_types[] = $acc_type;

    }
    print $FirstNames[0];

    setcookie("FirstName", $FirstNames[0], time()+3600*24*365*10, '/');
    setcookie("SIT_acc_type", $acc_type[0], time()+3600*24*365*10, '/');

    $stmt = $conn->prepare("UPDATE users SET last_log=? WHERE email=? AND password=?");
    $stmt->bind_param("sss", $time, $SearchEmail, $SearchPassword);
    $time = 'Time: '.date("h:i:sa").', Date: '.date("d/m/Y").'.';
    $SearchEmail = $OrigEmail;
    $SearchPassword = $OrigPassword;
    if ($stmt->execute()) {
        //echo "Success";
        Header('Location: ../?suc=1');
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM