我正在编写一个程序,它将通过 URL 接收值,然后将一个条目添加到 MySQL 数据库中,将其删除,或者如果其他人已经预订了该插槽,那么它不会让您删除它。
添加和删除函数如下:
function addBooking($id, $desk, $member, $date){
global $dbconn;
$query = $dbconn -> prepare("INSERT INTO booked (booking_id, desk_id, member_id, date_booked) VALUES (?,?,?,?)");
$query -> bind_param("iiis", $id, $desk, $member, $date);
$query->execute();
print '<div class="yours" title="Your Booking">Your Booking</div>';
$query -> close();
}
function delBooking($id, $desk){
global $dbconn;
$query = $dbconn -> prepare("DELETE FROM booked WHERE booking_id = ? AND desk_id = ?");
$query -> bind_param("ii", $id, $desk);
$query->execute();
print '<div class="free" title="Click To Book">Not Booked</div>';
$query -> close();
}
调用它们的代码是这样的:
$query = $dbconn -> prepare("SELECT firstname, lastname, booked.member_id, date_booked FROM members, booked WHERE (members.member_id = booked.member_id) AND booking_id = ? AND desk_id=?");
$query -> bind_param("ss", $booking_id, $desk_id);
if($query->execute() == true) {
$query -> bind_result($fname, $lname, $memid, $dbooked);
$query -> fetch();
if($fname){
if ($memid == $member_id)
{
delBooking($booking_id,$desk_id);
}
else
{
print '<div class="taken" title="Booked by <strong>'.$fname.' '.$lname.'</strong><br>On '.$dbooked.'">Booked</div>';
}
}else{
addBooking($booking_id,$desk_id,$member_id,$date);
}
}
它会增加预订罚款,并且还会告诉您是否其他人已经预订罚款,但如果您在自己的预订上再次运行它,它将给您错误:
Fatal error: Call to a member function bind_param() on a non-object in /var/www/new/functions/functions.php on line 80
我不确定为什么。这不是我的删除语句或任何东西,因为我可以将 addBooking 函数重命名为 delBooking 所以它是相同的工作代码,它仍然给我完全相同的错误:/