简体   繁体   English

我的PDO登录名出现黑屏

[英]I am getting a blank screen on my pdo login

here's some code i did. 这是我做的一些代码。 I am trying to login to a certain page if my username/password are both correct - but I keep on getting a blank white page even if the username/password are either CORRECT or WRONG! 如果我的用户名/密码都正确,我试图登录到某个页面-但是即使用户名/密码正确或错误,我仍会得到空白页面! I have 3 main files that I did. 我有3个主要文件。 Home.php, enter.php, and connection.php. Home.php,enter.php和connection.php。

Here's the code for Home.php: 这是Home.php的代码:

    <?php
session_start();
?>

<html>
<h1 align="center">Welcome To Home Page</h1>
<form method="POST">
<table border="0" align="center">

<tr>

<td>

<?php
echo $_SESSION["firstname"]; 
if($_SESSION["firstname"]==null)
{
?>
    <a href="enter.php">Login</a>
    <a href="registration.php">Registration</a>
    <a href="enter.php">Logout</a>
<?php
}
else
{
?>
<a href="enter.php">Logout</a>
<?php
}
?>
</td>

</tr>

<tr>
<td>
<img src="pix.jpg" width="500" length="500"/>
</td>

</table>
</form>
</html>

Here's the code for Enter.php: 这是Enter.php的代码:

    <html>

    <form action="connection.php" method="POST">
                        <ul>
                            <li>
                                Email: 
                                <input type="text" maxlength="30" name="emails" />
                            </li>

                            <li>
                                Password : 
                                <input type="password" maxlength="30" name="passwords" />
                            </li>
                            <input type="submit" maxlength="30" name="logins" value="Login" />

                        </ul>
                    </form>
    </html>

Here's the code for Connection.php: 这是Connection.php的代码:

    <?php
function getConnection(){
$db =  new PDO("mysql:host=localhost;dbname=demodatabase", "root","********");
$db ->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPION);
return $db;

$db = getConnection();
$stmt = $db->prepare("
    SELECT * FROM subscriber WHERE Email_id = :emails AND Password = :passwords
");
$stmt->bindParam(":emails"   , $users    );
$stmt->bindParam(":passwords", $passwords);
$stmt->execute();
$total = $db->rowCount();
$count = $stmt->rowCount(); 
    if ($count > 0) { 
    session_start(); 
    $_SESSION['firstname'] = 'yes'; 
    header('location: home.php'); 
    exit; 
    } 
}
?>

So why do I keep getting blank pages? 那么,为什么我总是得到空白页?

Look at your code: 查看您的代码:

    <?php
function getConnection(){
    // …
}
?>

You have everything in one function and never call that. 您将所有功能都集成到一个函数中,而永远不会调用它。 You need a closing curly brace here: 您需要在此处使用大括号:

function getConnection(){
    $db =  new PDO("mysql:host=localhost;dbname=demodatabase", "root","********");
    $db ->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPION);
    return $db;
}  // here

$db = getConnection();

Properly indenting your code would have helped. 适当地缩进代码会有所帮助。

On a side note, it's clear that you are storing passwords in plain text. 附带说明一下,很明显,您以纯文本形式存储密码。 Never do that! 绝对不要那样做! Use a good password hashing algorithm to hash passwords! 使用良好的密码哈希算法来哈希密码!

Also, using session_start or header after something has been sent to the browser is useless. 同样,在将某些内容发送到浏览器之后使用session_startheader是没有用的。 Watch the unwanted spaces before <?php . 注意<?php之前的多余空格。

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

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