作者:dtd3795290 | 来源:互联网 | 2023-05-19 01:28
1> Reenactor Ro..:
$query = "INSERT INTO appointmentinformation (ClientID, Length, Date, Month, Year, Time, Price) VALUES ('$clientid', '$length', '$date', '$month', '$year', '$time', '$price')";
$result = mysqli_query($connection, $query);
if ($result) {
header("Location:UserCP.php");
} else {
echo ("Could not insert data : " . mysqli_error($result) . " " . mysqli_errno());
}
mysqli_query返回的结果为null.这会将您发送到代码的else分支.然后你编写了mysqli_error($ result),它等于mysqli_error(null).
我读过的文档说是用查询的"链接"初始化变量.你这样做:
$cOnnection= mysqli_connect("$servername", "$username", "$password", "$dbname") or die("Could not connect to the database");
您现在想将其编码为mysqli_error($ connection)和mysqli_errno($ connection).
另外一个建议.在mysqli_connect语句后面添加此代码.
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}