我有一个外部程序,通过POST发送一些数据到我的服务器。我知道数据正在发送,因为我回应了POST及其罚款。但是当我添加INSERT INTO查询时它不起作用。这是我的代码:id = int(主键),home,mob = double,其余的是varchar。谢谢你提前。
<?php
$mysqli = new mysqli('####','###','###','user');
if (mysqli_connect_errno()) {
printf("Can't connect to SQL Server. Error Code %s\n", mysqli_connect_error($mysqli));
exit;
}
$date = $_POST['date'];
$desc = $_POST['desc'];
mysqli->query("INSERT INTO user_info (id, home, mob, type, description, date) VALUES (NULL,'','','',$desc,$date);");
mysql_real_escape_string($date),
mysql_real_escape_string($suburb));
$mysqli->close();
?>
答案 0 :(得分:0)
鉴于您的错误消息,您在$ mysqli-&gt;查询中缺少“$”,更正后的代码应为:
对于其他问题,请尝试获取正在发送到数据库的SQL,并在本地查询上运行它以查看是否存在缺少的SQL错误。
<?php
$date = mysql_real_escape_string( $_POST['date'] );
$desc = mysql_real_escape_string( $_POST['desc'] );
$query =<<<SQLQUERY
INSERT INTO user_info
(home, mob, type, description, date)
VALUES
('', '', '', $desc, $date)
SQLQUERY;
// Can you print out or get the value for $query?
$mysqli->query($query);
$mysqli->close();
?>