ms061210 0 Light Poster

Hi, can someone explain to me why my code is returning wrong output.
I want this code, First I have additional UPDATE query for a category 10, if it is not category 10 then it should ignore the update code. It is running correct if I input an item which belongs to category 10, but when an enter an item which does not belong to category 10 it does not ignore the update code, and its giving me errors.

here's my code:

 //get the product name, category id and product id of the item in the order number
             $result1 = mysqli_query($connection, "SELECT orderline.product_id, product_name, category_id, orderline.qty_order
                            FROM orderline
                            INNER JOIN products
                            ON products.product_id = orderline.product_id
                            WHERE category_id = 10
                            AND orderline.order_no = $orno ");
                    while($row1 = mysqli_fetch_assoc($result1)) { 
                      $pcname = $row1['product_name']; //get the product name
                      $qty_order1 = $row1['qty_order'];
                    }
                    echo $pcname;
            //explode the product name of personalize cake to get the size
            list($productName, $productSize) = explode("-", $pcname);
            $box = "Box $productSize";
            $cover = "Cover $productSize";
            $base = "Base $productSize";

           //query 6 for updating the base
         $qry6="UPDATE products
                SET quantity_on_hand = quantity_on_hand - $qty_order1
                WHERE category_id = 9
                AND product_name LIKE '%$box%'";
        if (!mysqli_query($connection,$qry6)) {
        die('Error: ' . mysqli_error($connection));
        }
        echo "q6";

          //query 7 for updating the cover
         $qry7="UPDATE products
                SET quantity_on_hand = quantity_on_hand - $qty_order1
                WHERE category_id = 9
                AND product_name LIKE '%$cover%'";

        if (!mysqli_query($connection,$qry7)) {
        die('Error: ' . mysqli_error($connection));
        }
        echo "q7";

          //query 7 for updating the base
         $qry8="UPDATE products
                SET quantity_on_hand = quantity_on_hand - $qty_order1
                WHERE category_id = 9
                AND product_name LIKE '%$base%'";
        if (!mysqli_query($connection,$qry8)) {
        die('Error: ' . mysqli_error($connection));
        }
        echo "q8";

If I am doing this the wrong way, is there a way where (1) Check using if else if there is a category 10 in the table(from db) (2) Perform my update quries if it exists and (3) ignore this update queries if category 10 does not exists. Please guide me on what to do. Thanks. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.