我不断从我的代码
中收到此错误Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\citizenssuites\site\pages\reservations.php on line 26
Warning: mysqli_error() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\citizenssuites\site\pages\reservations.php on line 26
Error querying database the first time
这是我的代码:
$query = "SELECT * FROM reservations, rooms, room_type";
$query .= " WHERE reservations.room_id=rooms.room_id";
$query .= " AND rooms.room_type_id=room_type.room_type_id";
$query .= " AND reservations.arrival < ".$arrival;
$query .= " AND reservations.departure > ".$departure;
$query .= " ORDER BY room_type.room_type_id";
$result = mysqli_query ($connection, $query) or die ('Error querying database the first time' . mysqli_error($connection));
我做错了什么?
答案 0 :(得分:2)
您没有先调用mysqli_connect
,否则失败。首先将$connection
设置为有效连接:
$connection = mysqli_connect("hostname", "username", "password");
if (mysqli_connect_error()) {
die("Error: " . mysqli_connect_error());
}
$result = mysqli_query($connection, ...);
答案 1 :(得分:0)
函数mysqli_connection
失败(或者您忘记调用它?)并返回null,当您稍后尝试$connection
使用mysqli_query
时会返回错误。