【发布时间】:2016-04-08 03:52:50
【问题描述】:
我在 mysql 中创建了一个表作为'cus_info'。它的列为“iD”“NAME”“PASSWORD”“eMAIL”。 iD 列是自动递增的。当新客户注册时,我想在此表中插入一个新行。为此,我用 PHP 编写了以下代码
<?php
error_reporting(0);
require "init.php";
$name = $_POST["name"];
$password = $_POST["password"];
$email = $_POST["email"];
$sql = "INSERT INTO `cus_info` (`name`, `password`, `email`) VALUES ('".$name."', '".$password."', '".$email."');";
if(!mysql_query($con, $sql)){
echo '{"message":"Unable to save the data to the database."}';
}
?>
但我总是收到“无法将数据保存到数据库”的消息 你能告诉我哪里出错了吗? 提前致谢。
【问题讨论】:
-
除了使用
mysql_*函数和对sql注入开放的代码?mysql_query第一个参数是$sql -
最后去掉
" "里面的; -
error_reporting(0);关闭错误消息关闭。 将其更改为error_reporting(E_ALL); -
在查询中显示你的 $con.also 语法错误。
-
这是您的自定义消息,我们需要实际的错误消息。试试这个:if(!mysqli_query($currentConnection, $sql)) { echo mysqli_error($currentConnection); } & 让我们知道确切的信息。