Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我的pdo登录时会出现一个空白屏幕_Php_Database_Login_Pdo - Fatal编程技术网

Php 我的pdo登录时会出现一个空白屏幕

Php 我的pdo登录时会出现一个空白屏幕,php,database,login,pdo,Php,Database,Login,Pdo,这是我做的一些代码。如果我的用户名/密码都正确,我会尝试登录到某个页面,但即使用户名/密码正确或错误,我仍然会得到一个空白的白色页面!我有三个主要的文件,我做了。Home.php、enter.php和connection.php 以下是Home.php的代码: <?php session_start(); ?> <html> <h1 align="center">Welcome To Home Page</h1> <form met

这是我做的一些代码。如果我的用户名/密码都正确,我会尝试登录到某个页面,但即使用户名/密码正确或错误,我仍然会得到一个空白的白色页面!我有三个主要的文件,我做了。Home.php、enter.php和connection.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>

欢迎来到主页
下面是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>

  • 电邮:
  • 密码:
下面是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; 
    } 
}
?>

那么为什么我总是得到空白页呢?

看看你的代码:

    <?php
function getConnection(){
    // …
}
?>
正确地缩进代码会有所帮助

另一方面,很明显,您正在以纯文本形式存储密码<永远不要那样做使用散列密码


此外,在将内容发送到浏览器后使用
session\u start
header
也没有用。在
white screen of death=error checking\display关闭之前查看不需要的空格一旦您将任何内容输出到浏览器,您就不能调用
session\u start()
header()
,除非您的示例代码中我弄错了-看起来您正在检查服务器日志,他们会有错误。我不认为
函数getConnection(){
在脚本文件的顶部有一个右括号add
error\u reporting(E\u ALL);ini\u set('display\u errors',1);
我现在该怎么办?我得到了以下错误:致命错误:未捕获异常'PDOException',消息'SQLSTATE[42S02]:找不到基表或视图:1146在C:\xampp\htdocs\registr2\connection.php:13堆栈跟踪:#0 C:\xampp\htdocs\registr2\connection.php(13):PDOStatement->execute()#1{main}在第13行的C:\xampp\htdocs\Registra2\connection.php中抛出了为什么我在上面遇到了这个错误-让我重复一遍-致命错误:未捕获异常“PDOException”,消息为“SQLSTATE[42S02]:找不到基表或视图:1146在C:\xampp\htdocs\registr2\connection.php:13堆栈跟踪:#0 C:\xampp\htdocs\registr2\connection.php(13):PDOStatement->execute()#1{main}在C:\xampp\htdocs\Registra2\connection.php中联机抛出13@user3047348这就是它所说的:您的表
subscriber
不存在。您必须先创建它,然后才能从中检索记录。我修复了这一问题-有表但名称不同-现在我得到的是-致命错误:调用未定义的方法PDO::rowCount()在C:\xampp\htdocs\registr2\connection.php的第14行,现在如何定义rowcount()?
function getConnection(){
    $db =  new PDO("mysql:host=localhost;dbname=demodatabase", "root","********");
    $db ->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPION);
    return $db;
}  // here

$db = getConnection();