我尝试将数据插入“studentremark”表。它有一个TEXT数据类型的字段。但是当我将数据插入该字段时,内容显示为“未定义”。这是代码“我正在使用ajax进行页面处理。
$faculty=$_REQUEST['faculty'];
$stcode=$_REQUEST['stcode'];
$rem=$_REQUEST['rem'];
$date = date('Y-m-d');
$sql = "INSERT INTO studentremark (STCODE, TID, rdate, remarks) VALUES (?, ?, ?, ?)";
$query = $mysqli->prepare($sql);
$query->bind_param('siss',$stcode, $faculty, $date, $rem);
if(!$query->execute())
{
echo("Some unknown error occurs, Item cannot be added.");
}
else
{
echo("Student remarks added successfully !!");
}
请帮忙。 提前谢谢。
答案 0 :(得分:1)
试试这个:
$sql = "INSERT INTO studentremark (STCODE, TID, rdate, remarks) VALUES (?, ?, ?, ?)";
$query = $mysqli->prepare($sql);
$query->bind_param('siss',$stcode, $faculty, $date, $rem);
$faculty=$_REQUEST['faculty'];
$stcode=$_REQUEST['stcode'];
$rem=$_REQUEST['rem'];
$date = date('Y-m-d');
if(!$query->execute()) {
echo("Some unknown error occurs, Item cannot be added.");
} else {
echo("Student remarks added successfully !!");
}
查看此php manual了解详情。
答案 1 :(得分:0)
查看您的代码,您有四个占位符,但尝试绑定五个值,修复它,尝试使用下面的代码
$sql = "INSERT INTO studentremark (STCODE, TID, rdate, remarks) VALUES (?, ?, ?, ?)";
$query = $mysqli->prepare($sql);
$query->bind_param('siss',$stcode, $date, $rem); // looking at columns i felt $faculty was extra so i removed it.
然后,要查看确切的错误消息,请使用以下过程执行查询
$query->execute() or die(mysqli_error());