php页面在尝试访问数据库时显示为空白


php page coming up blank when trying to access the database

我遇到了一个问题,我的插入代码似乎是错误的,但我不知道如何修复它。

它一直求助于我的页面是空白的,没有error_log,错误报告也不起作用,下面是代码

<?php
$connect = mysqli_connect("localhost","dfhdfhd","dfhdfh","fhgdfh");
$url = 'url';
$banner = 'banner';
$title = 'title';
$date = 'date';
$time = 'time';
$description = 'description';
$region = 'region';
$sponsors = 'sponsors';
mysqli_query($connect,"INSERT INTO information (url, banner, title, date, time, description, region, sponsors)
VALUES ('$url', '$banner', '$title', '$date' '$time', '$description', '$region', '$sponsors')";
?>

这里有一些错误。

首先,'$date'后面缺少逗号,打开的$connect, 缺少括号

此处:

mysqli_query($connect,"INSERT INTO information (url, banner, title, date, time, description, region, sponsors)
VALUES ('$url', '$banner', '$title', '$date', '$time', '$description', '$region', '$sponsors')");

在检查了错误之后,它会告诉你这些错误。

请参阅以下链接http://php.net/manual/en/mysqli.error.php和http://php.net/manual/en/function.error-reporting.php


您当前的代码对SQL注入是开放的。将准备好的语句PDO已准备好的报表一起使用。

如果某个查询由于某种原因不起作用,您应该添加error_reporting并显示mysqli错误:

<?php
error_reporting(-1);
$connect = mysqli_connect("localhost","dfhdfhd","dfhdfh","fhgdfh");
if (mysqli_connect_errno())
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$url = 'url';
$banner = 'banner';
$title = 'title';
$date = 'date';
$time = 'time';
$description = 'description';
$region = 'region';
$sponsors = 'sponsors';
$result = mysqli_query($connect,"INSERT INTO information (url, banner, title, date, time, description, region, sponsors)
VALUES ('$url', '$banner', '$title', '$date', '$time', '$description', '$region', '$sponsors')");
if (!result)
{
    echo("Error description: " . mysqli_error($connect));
}
?>

有关详细信息,请参阅:http://www.w3schools.com/php/func_mysqli_error.asp

还要确保php不是在某个地方执行的,在那里错误会得到响应,但不可见,因为它们在html之外或被css隐藏。

您还忘记了'$data''$time'之间的逗号,并关闭了mysqli_query函数。