Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't delete records from MySQL using PHP
    primarykey
    data
    text
    <p>I am writing a program that will receive values through URL and then will either add an entry to the MySQL database, delete it or if someone else has booked that slot then it will not let you delete it.</p> <p>The add and delete functions are as follows:</p> <pre><code>function addBooking($id, $desk, $member, $date){ global $dbconn; $query = $dbconn -&gt; prepare("INSERT INTO booked (booking_id, desk_id, member_id, date_booked) VALUES (?,?,?,?)"); $query -&gt; bind_param("iiis", $id, $desk, $member, $date); $query-&gt;execute(); print '&lt;div class="yours" title="Your Booking"&gt;Your Booking&lt;/div&gt;'; $query -&gt; close(); } function delBooking($id, $desk){ global $dbconn; $query = $dbconn -&gt; prepare("DELETE FROM booked WHERE booking_id = ? AND desk_id = ?"); $query -&gt; bind_param("ii", $id, $desk); $query-&gt;execute(); print '&lt;div class="free" title="Click To Book"&gt;Not Booked&lt;/div&gt;'; $query -&gt; close(); } </code></pre> <p>And the code that calls them is this:</p> <pre><code>$query = $dbconn -&gt; 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 -&gt; bind_param("ss", $booking_id, $desk_id); if($query-&gt;execute() == true) { $query -&gt; bind_result($fname, $lname, $memid, $dbooked); $query -&gt; fetch(); if($fname){ if ($memid == $member_id) { delBooking($booking_id,$desk_id); } else { print '&lt;div class="taken" title="Booked by &lt;strong&gt;'.$fname.' '.$lname.'&lt;/strong&gt;&lt;br&gt;On '.$dbooked.'"&gt;Booked&lt;/div&gt;'; } }else{ addBooking($booking_id,$desk_id,$member_id,$date); } } </code></pre> <p>It adds a booking fine and will also tell you if someone else has booked it fine, but if you run it again on your own booking it will give you the error:</p> <pre><code>Fatal error: Call to a member function bind_param() on a non-object in /var/www/new/functions/functions.php on line 80 </code></pre> <p>I'm not sure why. It's not my delete statement or anything because I can rename the addBooking function to delBooking so it's identical working code and it still gives me exactly the same error :/</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload