我正在編寫一個程序,它將通過URL接收值,然後將一個條目添加到MySQL數據庫中,刪除它或者如果其他人已經預訂了那個插槽,那麼它不會讓你刪除它。無法使用PHP刪除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
我不知道爲什麼。這不是我的delete語句或任何東西,因爲我可以將addBooking函數重命名爲delBooking,所以它的代碼是完全相同的,它仍然給出了完全相同的錯誤:/
是$ query - > bind_param(「ss」,$ booking_id,$ desk_id); functions.php中的第80行? –
是的。抱歉應該提到這一點。 – Steve
和你的PDO :: ERRMODE設置爲什麼? (PDO :: ERRMODE_SILENT; PDO :: ERRMODE_WARNING; PDO :: ERRMODE_EXCEPTION) –