Trying to display all records for a specific customer

Featured Imgs 23

Hi

I'm trying to make a system for someone I know and I have a customers page with a link to view orders and created another page to display the orders made for that specific customer name, I have got some php code on the page but it looks like it's only getting the first record of the customer name instead of all the records for the customer name

The code on the customer_orders.php page is below

<?php

                                /*error_reporting(E_ALL);
                                ini_set('display_errors', 1);*/

                                $CustomerName = $_GET['customername'];
                                //echo htmlentities($CustomerName);

                                $sql = "SELECT 
                                                    tblorders.InvoiceNumber,
                                                    tblorders.LorryName,
                                                    tblorders.CustomerName,
                                                    tblorders.DeliveryDate,
                                                    tblorders.PaymentMode,
                                                    tblorders.DeliveryMethod,
                                                    GROUP_CONCAT(CONCAT(tblorders.Quantity, ' of ', tblproducts.ProductName) SEPARATOR ', ') AS productnames, 
                                                    tblorders.InvoiceGenDate
                                                FROM tblorders 
                                                JOIN tblproducts ON tblproducts.id = tblorders.ProductId
                                                JOIN tblcustomers ON tblorders.CustomerName = tblcustomers.customername
                                                WHERE tblorders.CustomerName = :CustomerName";

                                $statement = $dbh->prepare($sql);
                                $statement->bindValue(':CustomerName', $CustomerName);
                                $result = $statement->execute();

                                if(!$result)
                                {
                                    //Query failed
    echo "Query failed";
    //Add debugging code
                                }
                                elseif(!$statement->rowCount())
{
    //No results returned
    echo "No user found for user " . htmlentities($CustomerName);
   //Add debugging code
}
                                else
{
    //A record was returned, display results
    $row = $statement->fetch(PDO::FETCH_ASSOC);

                                    ?>

                                <tbody>
                                    <tr>
                                        <td><?php echo $row['InvoiceNumber']; ?></td>
                                        <td><?php echo $row['LorryName'] ;?></td>
                                        <td><?php echo htmlentities(date("d-m-Y", strtotime($row['DeliveryDate'])));?></td>
                                        <td><?php echo $row['PaymentMode'];?></td>
                                        <td><?php echo $row['DeliveryMethod'];?></td>
                                        <td><?php echo htmlentities(date("d-m-Y", strtotime($row['InvoiceGenDate'])));?></td>
                                        <td><?php echo $row['productnames'];?></td>
                                        <td class="project-actions text-right">
                                        <a class="btn btn-primary btn-sm" href="#">View Invoice</a></td>
                                    </tr>
                            </tbody>

                            <?php

    //echo "Start Date: {$row['CustomerName']}<br/>\n";
}

$statement->closeCursor();
                                ?>

I'm not sure where I have gone wrong, I got the code from online and trying to do this code myself, could anyone take a look please and see what I have done wrong

PHP Fatal error: Uncaught Error: Unsupported operand types error

Featured Imgs 23

I am trying to make a system for office staff and delivery drivers so the office staff book the orders in and the delivery drivers are able to see what can see what orders there are for that day and for their lorry as will be multiple lorries/drivers. I am currently working on the sell product order page but I am getting the following error

It was working before I added extra code in so the customer name and lorry name is populated from the customers and lorries db table and when a customer name is selected, there is a next textarea box next to it that is populated with the customers address

[30-Oct-2024 15:30:07 UTC] PHP Fatal error: Uncaught Error: Unsupported operand types in /home/wwwbeechwoodsolu/public_html/sites/coal-lorry-system-two/sell_product.php:23
Stack trace:
#0 {main}
thrown in /home/wwwbeechwoodsolu/public_html/sites/coal-lorry-system-two/sell_product.php on line 23

On line 23 is

$_SESSION["cart_item"][$k]["quantity"] += $_POST["quantity"];

But don't think that line is the issue as was not showing any issue with that line or the code before I added extra code in

It's bit of long file to post the whole code here so I attached it as a txt file to this post

Below is the sections of code that contains the code I put in

//Code for Checkout
if(isset($_POST['checkout'])){
    $invoiceno= mt_rand(100000000, 999999999);
    $pid=$_SESSION['productid'];
    $quantity=$_POST['quantity'];
    $lorryname=$_POST['lorryname']; // I ADDED THIS LINE IN
    $customername=$_POST['customername']; // I ADDED THIS LINE IN
    $customeraddress=$_POST['customeraddress']; // I ADDED THIS LINE IN
    $pmode=$_POST['paymentmode'];
    $value=array_combine($pid,$quantity);
    foreach($value as $pdid=> $qty){
        $query=mysqli_query($con,"insert into tblorders(ProductId,Quantity,InvoiceNumber,LorryName,CustomerName,CustomerAddress,PaymentMode) values('$pdid','$qty','$invoiceno','$lorryname','$customername','$customeraddress','$pmode')") ; // I AMENDED THIS LINE TO ADD IN LORRYNAME, CUSTOMERNAME, CUSTOMERADDRESS
    }
    echo '<script>alert("Invoice generated successfully. Invoice number is "+"'.$invoiceno.'")</script>';  
    unset($_SESSION["cart_item"]);
    $_SESSION['invoice']=$invoiceno;
    echo "<script>window.location.href='invoice.php'</script>";

}



// I ADDED THIS CODE BLOCK IN
<div class="col-md-4 mb-10">
                                                    <label for="validationLorry03">Lorry</label>
                                                    <select  name="lorryname"  class="form-control" required>
                                                        <option value="">Select Lorry</option>
                                                        <?php
                                                $sql="SELECT * from  tbllorries";
                                                $query = $dbh -> prepare($sql);
                                                $query->execute();
                                                $results=$query->fetchAll(PDO::FETCH_OBJ);
                                                if($query->rowCount() > 0)
                                                {
                                                    foreach($results as $row)
                                                    {
                                                        ?> 
                                                        <option value="<?php  echo $row->lorryname;?>"><?php echo "Lorry Name: " . $row->lorryname . " | Area: " . $row->lorryarea . " | Day: " . $row->lorryday;?></option>
                                                        <?php 
                                                    }
                                                }
                                                        ?>
                                                    </select>
                                                </div>



// I ADDED THIS CODE BLOCK IN

<div class="col-md-4 mb-10">
                                                    <label for="validationLorry03">Lorry</label>
                                                    <select  name="lorryname"  class="form-control" required>
                                                        <option value="">Select Lorry</option>
                                                        <?php
                                                $sql="SELECT * from  tbllorries";
                                                $query = $dbh -> prepare($sql);
                                                $query->execute();
                                                $results=$query->fetchAll(PDO::FETCH_OBJ);
                                                if($query->rowCount() > 0)
                                                {
                                                    foreach($results as $row)
                                                    {
                                                        ?> 
                                                        <option value="<?php  echo $row->lorryname;?>"><?php echo "Lorry Name: " . $row->lorryname . " | Area: " . $row->lorryarea . " | Day: " . $row->lorryday;?></option>
                                                        <?php 
                                                    }
                                                }
                                                        ?>
                                                    </select>
                                                </div>

                                                <div class="col-md-4 mb-10">
                                                    <label for="validationCustom03">Customer Name</label>

                                                    <script>
                                                        function myFunction(){
                                                            var index = document.getElementById("customername").selectedIndex;
                                                            //alert(index);
                                                            var add = document.getElementById("customername").options[index].getAttribute("data-add");

                                                            document.getElementsByName("customeraddress")[0].value = add;
                                                        }
                                                    </script>

                                                    <select  name="customername" id="customername" class="form-control" required onchange="myFunction();">
                                                        <option value="">Select Customer</option>
                                                        <?php
                                                $sql="SELECT * from  tblcustomers";
                                                $query = $dbh -> prepare($sql);
                                                $query->execute();
                                                $results=$query->fetchAll(PDO::FETCH_OBJ);
                                                if($query->rowCount() > 0)
                                                {
                                                    foreach($results as $row)
                                                    {
                                                        ?> 
                                                        <option value="<?php echo $row->customername;?>" data-add="<?php echo $row->customeraddress;?>"><?php echo $row->customername;?></option>
                                                        <?php 
                                                    }
                                                }
                                                        ?>
                                                    </select>
                                                </div>
                                                <div class="col-md-4 mb-10">
                                                    <label for="validationCustom03">Customer Address</label>
                                                    <textarea rows=5 cols=5 name="customeraddress" class="form-control" placeholder="Enter Customer Address" required></textarea>
                                                </div>

remove first h3 tag and br tags in text

Featured Imgs 23

I have text that is displayed from a database and I have managed to remove the first h3 tag in the text by using the following code but I would also like to remove the two <br> tags that are before the paragraph of text

<h2 class="productsummaryheading mb-0">Product Summary</h2>
              <?php
$html= substr($description,0,strrpos(substr($description,0,300)," "));
$final = preg_replace('#<h3>(.*?)</h3>#', '', $html, 1);
echo $final;
?> ...<a href="<?php echo $_SERVER["REQUEST_URI"]; ?>#productdescription">Read More</a>

A example of the text paragraph is below

<br />          <br />  This 11.6 Chromebook is light, portable, rugged, and productive  the ultimate everyday learning tool. It brings Google Classroom, G Suite for Education, and todays ...<a href="/shop/laptops-tablets/Laptops/lenovo-100e-chromebook-g2-laptop-11-6-celeron-n4020-4gb-32gb-emmc-webcam-wi-fi-no-lan-usb-c-chrome-os#productdescription">Read More</a>

limit to 1 per where or clause

Category Image 101

I have managed to get blog posts displayed from each blog category but I want to limit it to 1 article from each blog category but unsure how to do it in the sql query I have, below is what I have so far

(SELECT BP.postID,postTitle,postSlug,postDesc,postDate,postImage
        FROM 
          blog_posts BP, blog_post_cats BPC 
    WHERE 
       BPC.catID = 6 AND BPC.postID = BP.postID OR BPC.catID = 5 AND BPC.postID = BP.postID OR BPC.catID = 4 AND BPC.postID = BP.postID OR BPC.catID = 1 AND BPC.postID = BP.postID
     )
    UNION
    (SELECT BP.postID,postTitle,postSlug,postDesc,postDate,postImage
        FROM 
          blog_posts BP, blog_post_cats BPC
    WHERE 
       BPC.catID = BPC.postID = BP.postID
     )