我遇到的问题似乎是我的插入代码错了,但我不知道如何解决它。
它继续使用我的页面空白,没有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')";
?>
答案 0 :(得分:3)
这里有一些问题。
首先,'$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 injection开放。使用prepared statements或PDO与prepared statements。
答案 1 :(得分:0)
如果由于某种原因查询不起作用,您应该添加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函数。