Jump to content

Cannot select data after update or delete sql statement in php in same action


CarolHCX

Recommended Posts

 

In the same $-POST , i wanted  to perform update and delete. With the updated and deleted database, I need to select the updated data from the database. However, it tells me:  Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in... .I am new to sql in php, is it true that i cannot perform sql in this way? Or is there any suggestion to perform select straight after deleting and updating?

CANCEL BOOK RESERVATION
if(isset($_POST['cancelres']))
{


        $query = "DELETE FROM reserved_books WHERE id='$resid';"; //delete reservation
        $query .="UPDATE reserved_books SET queue = queue - 1 WHERE bookid = '$bookid' AND queue > '$bookqueue';";//update queue number where reservation that queue behind/after/ the current reservation
        $query_run = mysqli_multi_query($connection, $query);

        if($query_run)
        {
          $_SESSION['success'] = "Reservation Cancelled";
        }
        else
        {
          $_SESSION['status'] = " Reservation Not Cancelled";    
        }

        $query= "SELECT title FROM books WHERE id = '$bookid';"; //get book title from db
        $query_run = mysqli_query($connection,$query);
        if(mysqli_num_rows($query_run)>0)
        {
            foreach ($query_run as $row) {
            $title = $row['title'];
            }
        }
        $bookres = "SELECT * FROM reserved_books WHERE bookid = '$bookid' AND queue = 1";
        $bookres_run = mysqli_query($connection,$bookres);
        foreach($bookres_run as $row)
        {
            $res_username = $row['username'];
            $res_id = $row['id'];
        }

        $query= "SELECT option_value FROM settings WHERE option_name = 'email_temp_rescollect'"; //get email template from db
        $query_run = mysqli_query($connection,$query);
        if(mysqli_num_rows($query_run)>0)
        {
            $row = mysqli_fetch_array($query_run);
            $rescollect_template = $row[0];
        }}

 

Link to comment
Share on other sites

If he result of a query is boolean (ie false) then the query failed. Check for failures. Easiest way is to put this line before your mysqli connection line

mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);

You must like living on the edge. Embedded variables in the query AND multi query. That's not just opening the door to SQL injection, it's demolishing the whole wall.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.