gpt4 book ai didi

php - Mysqli_query 返回 false 而 Mysqli_error 返回 NULL?

转载 作者:行者123 更新时间:2023-11-29 01:28:24 25 4
gpt4 key购买 nike

<分区>

我一直在创建预订系统和约会,但我的 SQL 语句不起作用。我一直在努力寻找解决方案,但无济于事。

下面列出的是我的 php 代码。我的第一个 SQL 语句运行良好并返回正确的 ClientID,但是,第二个 SQL 语句并没有将它全部插入到数据库中。我对结果做了 var_dumps,返回 bool(false),对结果做了 mysqli_error,返回 null。我最后的错误消息只显示回显消息,而不是 mysqli_error 或错误号。

(注意:某些值已更改/删除以保护数据)

<?php
session_start();
if(! $_SESSION['Username']) {
header("location:Index.php");
}
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "";
$tablename = "appointmentinformation";
$tablenamed = "clientinformation";

$connection = mysqli_connect("$servername", "$username", "$password", "$dbname") or die("Could not connect to the database");

$clientusername = $_SESSION['Username'];
$sql = "SELECT ClientID FROM $tablenamed WHERE Username = '$clientusername' LIMIT 1";
$results = mysqli_query($connection, $sql);
if (! $results) {
echo ("Could not select the data : " . mysql_error());
} else {
$datarows = mysqli_fetch_row($results);
$clientid = $datarows[0];
}

$date = $_POST["Date"];
$month = $_POST["Month"];
$year = $_POST["Year"];
$time = $_POST["Time"];
$length = $_POST["Length"];

$date = stripslashes($date);
$month = stripslashes($month);
$year = stripslashes($year);
$time = stripslashes($time);
$length = stripslashes($length);

$date = mysqli_real_escape_string($date);
$month = mysqli_real_escape_string($month);
$year = mysqli_real_escape_string($year);
$time = mysqli_real_escape_string($time);
$length = mysqli_real_escape_string($length);

$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());
}
?>

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com