白色死亡屏幕 - 从PHP格式插入MySQL

时间:2015-06-20 14:00:09

标签: php mysql

我有以下工作正在处理另一个项目,所以为了节省时间,我复制并粘贴它。这一次,我唯一改变的是连接细节和列的名称。当我点击提交时,我会看到死亡的白屏。

关于可能导致此问题的任何想法?

<?php
$con=mysqli_connect("localhost","username","password","database");
// Check connection
if (mysqli_connect_errno()) {
  echo "Failed to connect to Database, Contact Control: " . mysqli_connect_error();
}

// escape variables for security
$ID = mysqli_real_escape_string($con, $_POST['ID']);
$Time = mysqli_real_escape_string($con, $_POST['Time']);
$From = mysqli_real_escape_string($con, $_POST['From']);
$To = mysqli_real_escape_string($con, $_POST['To']);
$Comments = mysqli_real_escape_string($con, $_POST['Comments']);
$Actions = mysqli_real_escape_string($con, $_POST['Actions']);


$sql="INSERT INTO GNBR2015 (ID, Time, From, To, Comments, Actions) 
VALUES (
 '".$ID."',
 '".$Time."00',
 '".$From."', 
 '".$To."',
 '".$Comments."',
 '".$Actions."'
)

if (!mysqli_query($con,$sql)) {
  die('Error: ' . mysqli_error($con));
}
echo "record added";

mysqli_close($con);
?>

1 个答案:

答案 0 :(得分:0)

在您的查询Time中,FROM是保留字,应使用如下所示的backtique进行转义。见MySQL Documentation for more information

INSERT INTO GNBR2015 (ID, `Time`, `From`, `To`, Comments, Actions)