PNG  IHDR pHYs   OiCCPPhotoshop ICC profilexڝSgTS=BKKoR RB&*! J!QEEȠQ, !{kּ> H3Q5 B.@ $pd!s#~<<+"x M0B\t8K@zB@F&S`cbP-`'{[! eDh;VEX0fK9-0IWfH  0Q){`##xFW<+*x<$9E[-qWW.(I+6aa@.y24x6_-"bbϫp@t~,/;m%h^ uf@Wp~<5j>{-]cK'Xto(hw?G%fIq^D$.Tʳ?D*A, `6B$BB dr`)B(Ͱ*`/@4Qhp.U=pa( Aa!ڈbX#!H$ ɈQ"K5H1RT UH=r9\F;2G1Q= C7F dt1r=6Ыhڏ>C03l0.B8, c˱" VcϱwE 6wB aAHXLXNH $4 7 Q'"K&b21XH,#/{C7$C2'ITFnR#,4H#dk9, +ȅ3![ b@qS(RjJ4e2AURݨT5ZBRQ4u9̓IKhhitݕNWGw Ljg(gwLӋT071oUX**| J&*/Tު UUT^S}FU3S ԖUPSSg;goT?~YYLOCQ_ cx,!k u5&|v*=9C3J3WRf?qtN (~))4L1e\kXHQG6EYAJ'\'GgSSݧ M=:.kDwn^Loy}/TmG X $ <5qo</QC]@Caaᄑ.ȽJtq]zۯ6iܟ4)Y3sCQ? 0k߬~OCOg#/c/Wװwa>>r><72Y_7ȷOo_C#dz%gA[z|!?:eAAA!h쐭!ΑiP~aa~ 'W?pX15wCsDDDޛg1O9-J5*>.j<74?.fYXXIlK9.*6nl {/]py.,:@LN8A*%w% yg"/6шC\*NH*Mz쑼5y$3,幄'L Lݛ:v m2=:1qB!Mggfvˬen/kY- BTZ(*geWf͉9+̳ې7ᒶKW-X潬j9(xoʿܔĹdff-[n ڴ VE/(ۻCɾUUMfeI?m]Nmq#׹=TR+Gw- 6 U#pDy  :v{vg/jBFS[b[O>zG499?rCd&ˮ/~јѡ򗓿m|x31^VwwO| (hSЧc3- cHRMz%u0`:o_F@8N ' p @8N@8}' p '#@8N@8N pQ9p!i~}|6-ӪG` VP.@*j>[ K^<֐Z]@8N'KQ<Q(`s" 'hgpKB`R@Dqj '  'P$a ( `D$Na L?u80e J,K˷NI'0eݷ(NI'؀ 2ipIIKp`:O'`ʤxB8Ѥx Ѥx $ $P6 :vRNb 'p,>NB 'P]-->P T+*^h& p '‰a ‰ (ĵt#u33;Nt̵'ޯ; [3W ~]0KH1q@8]O2]3*̧7# *p>us p _6]/}-4|t'|Smx= DoʾM×M_8!)6lq':l7!|4} '\ne t!=hnLn (~Dn\+‰_4k)0e@OhZ`F `.m1} 'vp{F`ON7Srx 'D˸nV`><;yMx!IS钦OM)Ե٥x 'DSD6bS8!" ODz#R >S8!7ّxEh0m$MIPHi$IvS8IN$I p$O8I,sk&I)$IN$Hi$I^Ah.p$MIN$IR8I·N "IF9Ah0m$MIN$IR8IN$I 3jIU;kO$ɳN$+ q.x* tEXtComment

Viewing File: /home/u423589436/domains/kingshomeandcomfort.com/public_html/single-product.php

<?php
session_start();
include("connection.php");
if (isset($_POST['add_wish_btn'])) {
    $product_id = $_POST['product_id'];
    $username = $_POST['username'];

    // Check if this item is already in the wishlist (optional but recommended)
    $check_sql = "SELECT * FROM wishlist WHERE product_id='$product_id' AND username='$username'";
    $check_query = mysqli_query($conn, $check_sql);

    if (mysqli_num_rows($check_query) == 0) {
        $insert_sql = "INSERT INTO wishlist (product_id, username) VALUES ('$product_id', '$username')";
        if (mysqli_query($conn, $insert_sql)) {
            echo "<script>alert('Added to wishlist!');</script>";
        } else {
            echo "<script>alert('Failed to add to wishlist.');</script>";
        }
    } else {
        echo "<script>alert('Already in your wishlist.');</script>";
    }
}
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["add_to_cart_btn"])) {
    $product_id = $_POST["product_id"];
    $user_id = $_POST["user_id"];

    // Check if already in cart
    $check_sql = "SELECT * FROM cart_tb WHERE product_id = '$product_id' AND user_id = '$user_id'";
    $check_query = mysqli_query($conn, $check_sql);

    // Prepare redirect
    $base_url = strtok($_SERVER["REQUEST_URI"], '?'); // e.g., /single-product.php
    $params = $_GET; // preserve existing query like id=3

    if (mysqli_num_rows($check_query) > 0) {
        $params['status'] = 'exists';
    } else {
        $insert_sql = "INSERT INTO cart_tb (product_id, user_id) VALUES ('$product_id', '$user_id')";
        if (mysqli_query($conn, $insert_sql)) {
            $params['status'] = 'added';
        } else {
            $params['status'] = 'error';
        }
    }

    // Build final URL and redirect
    $redirect_url = $base_url . '?' . http_build_query($params);
    header("Location: $redirect_url");
    exit();
}

// Show alerts
if (isset($_GET['status'])) {
    echo "<script>";
    switch ($_GET['status']) {
        case 'exists':
            echo "alert('Product is already in your cart.');";
            break;
        case 'added':
            echo "alert('Product added to cart successfully.');";
            break;
        case 'error':
            echo "alert('Something went wrong. Please try again.');";
            break;
    }
    echo "</script>";
}

// Display JavaScript alerts after redirection
if (isset($_GET['status'])) {
    echo "<script>";
    switch ($_GET['status']) {
        case 'exists':
            echo "alert('Product is already in your cart.');";
            break;
        case 'added':
            echo "alert('Product added to cart successfully.');";
            break;
        case 'error':
            echo "alert('Something went wrong. Please try again.');";
            break;
    }
    echo "</script>";
}
?>
<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>
        <?php
    
    include("connection.php");
    $sqla="SELECT * FROM products WHERE id='$_GET[id]'";
    $querya=mysqli_query($conn,$sqla);
    $row11=mysqli_fetch_array($querya);
    echo $row11["product_name"]." - King's Home & Comfort";
    $stock_quantity=$row11["stock_quantity"];
    $sales_price=$row11["sales_price"];
 $original_price=$row11["original_price"];
    $check_for_similar_name="SELECT * FROM viewed_products_tb WHERE product_name='$row11[product_name]' AND username='$_SESSION[username]'";
    $query_the_check=mysqli_query($conn, $check_for_similar_name);
    $no_of_similar_names=mysqli_num_rows($query_the_check);
    if($no_of_similar_names==0){

    $insert_viewed_product="INSERT INTO viewed_products_tb (username, photo_path, product_name) VALUES ('$_SESSION[username]', '$row[photo_path]', '$row[product_name]')";

    $insert_query=mysqli_query($conn, $insert_viewed_product);
}

        ?>
    
    </title>

    <?php include("header-links.php"); ?>

    <style>
        @media only screen and (min-width: 767px) {
            #register{
                display: none;
            }

        }

        #alert {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 9999;
  display: none;
  width: 250px;
  font-size: 25px;
  text-align: center;
  padding: 10px;
  font-weight: bolder;
  border-radius: 10px;
}


    </style>


    
</head>
<body class="biolife-body">

   
   <?php include("header.php"); ?>

    <!--Navigation section-->
    <div class="container">
        <nav class="biolife-nav">
            <ul>
                <li class="nav-item"><a href="index.php" class="permal-link">Home</a></li>
               
                <li class="nav-item"><span class="current-page">
                    <?php
                    /*
                     include("connection.php"); 
                     $sql="SELECT * FROM products WHERE id='$_GET[id]'";
                     $query=mysqli_query($conn,$sql);
                     $row=mysqli_fetch_array($query);
*/
                     echo $row11["product_name"];
                     ?>
                
                </span></li>
            </ul>
        </nav>
    </div>

    <div class="page-contain single-product">
        <div class="container">

        <!-- Main content -->
        <div id="main-content" class="main-content">

         <!-- summary info -->
         <div class="sumary-product single-layout">
         <div class="media">
    <ul class="biolife-carousel slider-for" data-slick='{"arrows":false,"dots":false,"slidesMargin":30,"slidesToShow":1,"slidesToScroll":1,"fade":true,"asNavFor":".slider-nav"}'>
        <?php 
        // Retrieve the product images from the database
        $query = "SELECT * FROM products WHERE id='$_GET[id]'";
        $result = mysqli_query($conn, $query);
        $row=mysqli_fetch_array($result);

        echo "<img src='admin/$row[photo_path]' class='img-fluid' style='max-width: 100%; min-width: 100%; max-height: 450px; min-height: 500px; object-fit: cover;'>";
        ?>
    </ul>


   
</div>


                    
<?php
include("connection.php");

// Pagination variables
$limit = 24; // Number of products per page
$page = isset($_GET['page']) ? $_GET['page'] : 1; // Current page number

// Calculate the offset for the SQL query
$offset = ($page - 1) * $limit;

// Retrieve products from the database with pagination
$sql2 = "SELECT * FROM products WHERE id='$_GET[id]' LIMIT $limit OFFSET $offset";
$query2 = mysqli_query($conn, $sql2);
$row2=mysqli_fetch_array($query2);

    // Your loop code here
    $id = $row["id"];
    $product_name = $row["product_name"];
    $product_category = $row["product_category"];
    $sales_price = $row["sales_price"];
    $original_price = $row["original_price"];
    $description = $row["description"];
    $photo_path = $row["photo_path"];
    $created_at = $row["created_at"];


    // Truncate long product and description names
    $trimmed_product_name = strlen($product_name) > 15 ? substr($product_name, 0, 15) . "..." : $product_name;
    $trimmed_description = strlen($description) > 15 ? substr($description, 0, 35) . "..." : $description;

  
;
    $sql3="SELECT * FROM reviews WHERE product_id='$_GET[id]'";
    $query3=mysqli_query($conn,$sql3);
    $no_of_reviews=mysqli_num_rows($query3);    
    
?>

                    <div class="product-attribute">
                        <h3 class="title" style="font-size: 25px;"><?php echo $row2["product_name"]; ?></h3>
                        <div class="rating">
                            <p><b class="review-count" style="font-size: 17px;">(<b style="color: ;"><?php echo $no_of_reviews; ?></b> Verified Reviews)</b></p>
                            
                        </div>
                        <div>
                           <h4 style="background-color: whitesmoke; color: black; font-weight: bolder; padding: 10px; border-radius: 5px;"><?php echo $row11['stock_quantity']; ?> In Stock</h4>
                        </div>
                            <div class="price">
                            <ins>
    <span class="price-amount" style="font-size: 30px">
        <span class="currencySymbol">&#8358;</span> <?php echo number_format($sales_price, 2); ?>
    </span>
</ins>
<del>
    <span style="color: grey;" class="price-amount">
        <span class="currencySymbol">&#8358;</span>
        <?php echo number_format($original_price, 2); ?>
    </span>
</del>

 &nbsp; <?php
                            
                            // Calculate the percentage discount
$percentage_discount = (($original_price - $sales_price) / $original_price) * 100;

// Round off to 2 decimal places
$percentage_discount = number_format($percentage_discount, 2);

echo $percentage_discount."% discount";

                            ?></span>
                            
                        </div>


    <style>

@media screen and (min-width: 768px) {
  /* CSS rules specific to desktop */
  #buy-now-link {
   width: 50%;
  }

  .social-list{
    text-align: left;
  }

}

@media screen and (max-width: 767px) {
#buy-now-link {
   width: 100%;
  }
}
        
    </style>

<br>


<div class="">
    <div class="d-flex justify-content-between">

    <?php
    if(!isset($_SESSION["username"])){
        ?>

        <a href="#" class="btn btn-danger btn-lg btn-rounded" style="background-color: purple; border: none; border-radius: 20px; width: 100%" data-toggle="modal" data-target="#guestCheckoutModal">Guest Checkout <i class="fa fa-arrow-right"></i></a>

        <?php } ?>   

        <br>
      
<?php

if(isset($_SESSION["username"])){

    include("connection.php");
    $sql="SELECT * FROM users WHERE username='$_SESSION[username]'";
    $query=mysqli_query($conn, $sql);
    $row=mysqli_fetch_array($query);

    $id = intval($_GET['id']); // ensure $id is set and safe
    $sql2="SELECT * FROM products WHERE id=$id";
    $query2=mysqli_query($conn, $sql2);
    $row2=mysqli_fetch_array($query2);

    $unit_price = $row2['sales_price'];
    ?>

    <form action="checkout.php" method="POST" id="checkout-form">
        <input type="hidden" name="username" value="<?php echo $_SESSION['username']; ?>">
        <input type="hidden" name="full_name" value="<?php echo $row['full_name']; ?>">
        <input type="hidden" name="email" value="<?php echo $row['email']; ?>">
        <input type="hidden" name="shipping_address" value="<?php echo $row['shipping_address']; ?>">
        <input type="hidden" name="unit_price" id="unit_price" value="<?php echo $unit_price; ?>">
        <input type="hidden" name="amount" id="amount" value="<?php echo $unit_price; ?>">
        <input type="hidden" name="product_name" value="<?php echo $row2['product_name']; ?>">

        <!-- Quantity Controls -->
        <div style="margin-bottom: 15px;">
            <label for="quantity">Quantity:</label><br>
            <button type="button" onclick="changeQuantity(-1)">-</button>
            <input type="text" name="quantity" id="quantity" value="1" readonly 
       style="width: 60px; height: 30px; text-align: center; font-size: 16px; border: 1px solid #ccc; border-radius: 5px;">

            <button type="button" onclick="changeQuantity(1)">+</button>
        </div>

        <!-- Display updated price -->
        <div>
            <strong>Total Price: ₦<span id="display_price"><?php echo $unit_price; ?></span></strong>
        </div>
<hr>
        <button type="submit" name="checkout_btn" id="buy-now-link" style="background-color: purple; border: none; border-radius: 20px; width: 100%" class="btn btn-danger btn-lg btn-rounded"><i class="fa fa-shopping-cart"></i> Buy Now <i class="fa fa-arrow-right"></i></button>
    </form>
<br><br>
    <!-- The wishlist form -->
    <form action="" method="POST">
        <input type="hidden" name="product_id" value="<?php echo $_GET['id'] ?>">
        <input type="hidden" name="username" value="<?php echo $_SESSION['username']; ?>">
        <button type="submit" class="btn btn-success btn-lg btn-rounded" style="background-color: black; border-radius: 20px; width: 100%; border: none;" name="add_wish_btn">+ Wish List</button>
    </form>

   <script>
    const stockQuantity = <?php echo intval($row2['stock_quantity']); ?>; // use PHP variable directly

    function changeQuantity(change) {
        let quantityInput = document.getElementById("quantity");
        let unitPrice = parseFloat(document.getElementById("unit_price").value);

        let quantity = parseInt(quantityInput.value);
        quantity += change;

        if (quantity < 1) quantity = 1;
        if (quantity > stockQuantity) quantity = stockQuantity;

        let total = quantity * unitPrice;

        quantityInput.value = quantity;
        document.getElementById("amount").value = total.toFixed(2);
        document.getElementById("display_price").innerText = total.toFixed(2);
    }
</script>

<?php } ?>

          
        <br>

                                                <?php
                                                echo "
                                                 <center>
                                                  <form action='' method='POST'>
                                                   <input type='hidden' name='product_id' value='$id'>
                                                   <input type='hidden' name='user_id' value='$_SESSION[user_id]'>
                                                   <button type='submit' style='border-radius: 20px; border: none; color: white; width: 100%; background-color: purple' name='add_to_cart_btn' class='btn btn-danger btn-lg btn-rounded'>Add to cart</button>
                                                  </form>
                                                  </center>
                                                   
                                                 ";

                                                 ?> 
                                                 
                                                

    </div>
</div>

                      
                    </div>


                    <div class="action-form">

                        <span class="title"></span>
                      
                       
                        <div class="social-media">
                            <span class="title">Do you have any inquiries? Our team is available for a chat.</span>
                            <ul class="social-list">
                                <li><a href="https://wa.me/message/QU5WWJ3BXKM2J1" class="social-link" target="_blank"><i class="fab fa-whatsapp" aria-hidden="true"></i></a></li>
                                <li><a href="https://www.facebook.com/share/p/1EwX5w6TLF/?mibextid=xfxF2i" target="_blank" class="social-link"><i class="fab fa-facebook" aria-hidden="true"></i></a></li>
                                
                            </ul>
                        </div>
                        <div class="acepted-payment-methods">
                            <ul class="payment-methods">
                                <li><img src="https://tse4.mm.bing.net/th/id/OIP.APcFwdC8B5rAEm5CM56alwHaEc?rs=1&pid=ImgDetMain" alt="" width="51" height="36"></li>
                              
                            </ul>
                        </div>
                    </div>
                </div>

                <!-- Tab info -->
                <div class="product-tabs single-layout biolife-tab-contain">
                    <div class="tab-head">
                        <ul class="tabs">
                            <li class="tab-element active"><a href="#tab_1st" class="tab-link">Description</a></li>
                            <li class="tab-element" ><a href="#tab_4th" class="tab-link">Customer Reviews <sup>(<?php echo $no_of_reviews; ?>)</sup></a></li>
                        </ul>
                    </div>
                    <div class="tab-content">
                        <div id="tab_1st" class="tab-contain desc-tab active">
                            <p class="desc"><?php echo $description; ?></p>
                            
                        </div>
                       
                        
                        <div id="tab_4th" class="tab-contain review-tab">
                            <div class="container">
                                <div class="row">
                                    <div class="col-lg-5 col-md-5 col-sm-6 col-xs-12">
                                        <div class="rating-info">
                                            
                                             <br>
                                          

                                            <?php
                                             include("connection.php");
                                             $select_reviews="SELECT * FROM reviews WHERE product_id='$_GET[id]' ORDER BY RAND() LIMIT 5";
                                             $select_query=mysqli_query($conn,$select_reviews);
                                             while($row=mysqli_fetch_array($select_query)):   
                                                
                                                $your_name = $row["your_name"];
                                                $your_email = $row["your_email"];
                                                $your_comment = $row["your_comment"];
                                                $product_id = $row["product_id"];
                                                
                                                 // Get the first and last letters of the your_name string
    $first_letter = substr($your_name, 0, 1);
    $last_letter = substr($your_name, -1);
    
    // Calculate the number of stars needed in the middle
    $num_stars = strlen($your_name) - 2;
    
    // Generate a string of stars with the same length as the number of stars needed
    $stars = str_repeat('*', $num_stars);
    
    // Concatenate the first letter, stars, and last letter
    $your_name_with_stars = $first_letter . $stars . $last_letter;
                                            ?>

                                            
<span class="mt-0"><b><?php echo $your_name; ?></b></span>
       <p style="font-family: roboto;"><?php echo $your_comment; ?></p>
       


                                            <?php endwhile; ?>

                                             
                      
 
        

                                          
<!-- Button to trigger the modal -->
<button type="button" class="btn btn-danger" style="background-color: purple; border: none;" data-toggle="modal" data-target="#myModal">
  See all reviews
</button>

                                            
                                        </div>
                                    </div>
                                    <div class="col-lg-7 col-md-7 col-sm-6 col-xs-12">
                                        <div class="review-form-wrapper">
                                            <span class="title">Submit your review</span>
                                            <form action="" name="frm-review" method="post">
                                               
                                                <p class="form-row">
                                                    <input type="text" name="your_name" value="" required placeholder="Your name">
                                                </p>

                                                
                                                    <input type="hidden" name="your_email" value="" placeholder="Email address">
                                                
                                                
                                                <p class="form-row">
                                                    <textarea name="your_comment" id="txt-comment" cols="30" rows="10" placeholder="Write your review here..."></textarea>
                                                </p>

                                                <?php echo "<input type='hidden' name='product_id' value='$_GET[id]'>"; ?>
                                                
                                                <p class="form-row">
                                                    <button type="submit" style="background-color: purple; border: none;" name="submit">submit review</button>
                                                </p>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                                

  

        
                            </div>
                        </div>
                    </div>
                </div>

     

                <!-- related products -->
                <div class="product-related-box single-layout">
                    <div class="biolife-title-box lg-margin-bottom-26px-im">
                        <span class="fas fa-shopping-cart"></span>
                        <span class="subtitle">All the best products for You</span>
                        <h3 class="main-title">Related Products</h3>
                    </div>
                  
                    <style>
    .product-title a{
        font-weight: bolder;
    }
</style>



    <div class="block-item recently-products-cat md-margin-bottom-39">
    <ul class="products-list biolife-carousel nav-center-02 nav-none-on-mobile" data-slick='{"rows":1,"arrows":true,"dots":false,"infinite":false,"speed":400,"slidesMargin":0,"slidesToShow":5, "responsive":[{"breakpoint":1200, "settings":{ "slidesToShow": 3}},{"breakpoint":992, "settings":{ "slidesToShow": 3, "slidesMargin":30}},{"breakpoint":768, "settings":{ "slidesToShow": 2, "slidesMargin":10}}]}'>

        <?php
        include("connection.php");

        $sql = "SELECT * FROM products WHERE product_category='$product_category' AND id!='$_GET[id]'";
        $query = mysqli_query($conn, $sql);

        while ($row = mysqli_fetch_array($query)):
            // Your loop code here
            $id = $row["id"];
            $product_name = $row["product_name"];
            $product_category = $row["product_category"];
            $sales_price = $row["sales_price"];
            $original_price = $row["original_price"];
            $description = $row["description"];
            $photo_path = $row["photo_path"];
            $created_at = $row["created_at"];

            // Truncate long product and description names
            $trimmed_product_name = strlen($product_name) > 15 ? substr($product_name, 0, 15) . "..." : $product_name;
            $trimmed_description = strlen($description) > 15 ? substr($description, 0, 35) . "..." : $description;
        
          
        ?>

        <li class="product-item">
            <div class="contain-product layout-02">
                <div class="product-thumb">
                <?php echo "
            <a href='single-product.php?id=$row[id]' class='link-to-product'>
                <img src='admin/$photo_path' alt='$product_name' width='270' style='max-height: 270px; min-height: 270px; object-fit: cover' class='product-thumnail'>
            </a>
            ";
            ?>
                </div>
                <div class="info">
                <h4 class="product-title">
                <?php echo "<a href='single-product.php?id=$row[id]' class='pr-name'>$trimmed_product_name</a>"; ?>
                </h4>
                </div>

                <div class="price text-center" style="font-weight: bolder;">
                <ins style="text-decoration: none;">
    <span class="price-amount">
        <span class="currencySymbol">&#8358;</span>
        <?php echo number_format($sales_price, 2); ?>
    </span>
</ins>
<del>
    <span style="color: red;" class="price-amount">
        <span class="currencySymbol">&#8358;</span>
        <?php echo number_format($original_price, 2); ?>
    </span>
</del>
                <div class="buttons">
                   <?php echo "
                   <a href='single-product.php?id=$row[id]' class='btn btn-danger' style='background-color: purple; border: none;'>Learn more/Buy</a>
                    ";
                    ?>
                   </div>
            
                </div>

            </div>
        </li>

        <?php endwhile; ?>

    </ul>
</div>

                </div>
                
            </div>
        </div>
       </div>

     <!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="myModalLabel">
        <?php
        include("connection.php");
        $sql="SELECT * FROM reviews WHERE product_id='$_GET[id]'";
        $query=mysqli_query($conn,$sql);
       
            $no_of_rows=mysqli_num_rows($query);
            if($no_of_rows>0){
        
        ?>
        
        Here is what people have to say about <i style="font-weight: bolder; color: red"><?php echo $row2["product_name"]; ?></i></span>
        
        <?php 
                
            }else{
                echo '
                <div class="alert-warning p-3">No reviews yet! Be the first to give your thoughts</div>
                ';
            }
        
        
        
        ?>
                </h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
     <?php
$select_all_reviews = "SELECT * FROM reviews WHERE product_id = '$_GET[id]' ORDER BY RAND()";
$query_selection=mysqli_query($conn,$select_all_reviews);
        while($row=mysqli_fetch_array($query_selection)):
        ?>

      <span class="mt-0"><b><?php echo $row["your_name"]; ?></b></span>
       <p style="font-family: roboto;"><?php echo $row["your_comment"]; ?></p>
       
       <hr>

       <?php endwhile; ?>
    
    </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>



<!-- Guest Checkout Modal -->
<div class="modal fade" id="guestCheckoutModal" tabindex="-1" role="dialog" aria-labelledby="guestCheckoutModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
    
      <div class="modal-header">
        <h5 class="modal-title" id="guestCheckoutModalLabel">Guest Checkout</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>

      <div class="modal-body">
        <!-- Checkout Form -->
        <form action="guest-checkout.php" method="POST">
          <div class="form-group">
            <label for="fullName">Full Name*</label>
            <input type="text" class="form-control" id="fullName" name="full_name" required>
          </div>

          <div class="form-group">
            <label for="phone">Email*</label>
            <input type="email" class="form-control" id="phone" name="email" required>
          </div>

          <div class="form-group">
            <label for="shippingAddress">Shipping Address*</label>
            <textarea class="form-control" id="shippingAddress" placeholder="E.g. 42 Palm Street, Victoria Island, Lagos, Nigeria." name="shipping_address" required></textarea>
          </div>

          <?php
          /*
          include("connection.php");

          // Assuming you're checking out a single product; update as needed for multiple items
          $sql = "SELECT p.sales_price, p.product_name 
                  FROM cart_tb c 
                  JOIN products p ON c.product_id = p.id 
                  LIMIT 1";

          $query = mysqli_query($conn, $sql);
          $row = mysqli_fetch_array($query);

          $sales_price = $row['sales_price'];
          $product_name = $row['product_name'];
          */
          ?>

<!-- Quantity Selector -->
<div class="form-group">
  <label for="quantity">Quantity</label>
  <div class="input-group" style="max-width: 140px;">
    <div class="input-group-prepend">
      <button class="btn btn-outline-secondary btn-minus" type="button">−</button>
    </div>
    <input 
      type="number" 
      class="form-control text-center" 
      id="quantity" 
      name="quantity" 
      value="1" 
      min="1" 
      max="<?= $row11['stock_quantity']; ?>"
    >
    <div class="input-group-append">
      <button class="btn btn-outline-secondary btn-plus" type="button">+</button>
    </div>

  </div>
</div>



          <!-- Display Total Price -->
          <div class="form-group">
            <label>Total Price (₦):</label>
            <p><strong id="totalPrice"> <?php echo $row11["sales_price"]; ?></strong></p>
          </div>

          <!-- Hidden Inputs for Backend -->
          <input type="hidden" id="amount" value="<?php echo $row11['sales_price']; ?>" name="amount">
          <input type="hidden" id="product_name" value="<?php echo $row11['product_name']; ?>" name="product_name">

          <button type="submit" name="guest_checkout" class="btn btn-danger">Continue</button>
        </form>
      </div>

      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>



<!-- JavaScript to Handle Quantity Changes -->
<script>
document.addEventListener("DOMContentLoaded", function () {
  const minusBtn = document.querySelector(".btn-minus");
  const plusBtn = document.querySelector(".btn-plus");
  const quantityInput = document.getElementById("quantity");
  const totalPriceEl = document.getElementById("totalPrice");
  const amountInput = document.getElementById("amount");

  const basePrice = parseFloat(<?= $row11["sales_price"]; ?>);
  const stockQuantity = parseInt(<?= $stock_quantity ?>);

  function updateTotal() {
    const quantity = parseInt(quantityInput.value);
    const total = basePrice * quantity;
    totalPriceEl.textContent = total.toFixed(2);
    amountInput.value = total.toFixed(2);
  }

  minusBtn.addEventListener("click", () => {
    let value = parseInt(quantityInput.value);
    if (value > 1) {
      quantityInput.value = value - 1;
      updateTotal();
    }
  });

  plusBtn.addEventListener("click", () => {
    let value = parseInt(quantityInput.value);
    if (value < stockQuantity) {
      quantityInput.value = value + 1;
      updateTotal();
    }
  });

  quantityInput.addEventListener("change", () => {
    let value = parseInt(quantityInput.value);
    if (isNaN(value) || value < 1) {
      value = 1;
    } else if (value > stockQuantity) {
      value = stockQuantity;
    }
    quantityInput.value = value;
    updateTotal();
  });

  // Initialize total on page load
  updateTotal();
});
</script>

<?php include("footer.php"); ?>
<?php include("footer-links.php"); ?>

<script>
document.addEventListener("DOMContentLoaded", function() {
  var alertDiv = document.getElementById("alert");
  alertDiv.style.display = "block";

  setTimeout(function() {
    alertDiv.style.display = "none";
  }, 5000);
});
</script>



</body>
</html>



<?php

if(isset($_POST["submit"])){

include("connection.php");

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $rating = $_POST['rating'];
    $name = $_POST['your_name'];
    $email = $_POST['your_email'];
    $comment = $_POST['your_comment'];
    $productId = $_POST['product_id'];

    // Sanitize the form inputs (recommended)
    $rating = $conn->real_escape_string($rating);
    $name = $conn->real_escape_string($name);
    $email = $conn->real_escape_string($email);
    $comment = $conn->real_escape_string($comment);
    $productId = $conn->real_escape_string($productId);

    // Perform further validation if necessary

    // Prepare the SQL query
    $query = "INSERT INTO reviews (rating, your_name, your_email, your_comment, product_id) VALUES ('$rating', '$name', '$email', '$comment', '$productId')";

    // Execute the query
    if ($conn->query($query) === true) {
        echo '<div id="alert" class="alert-success">Review sent <i class="fa fa-check"></i></div>';
    } else {
        echo 'Error submitting review: ' . $conn->error;
    }

    // Close the database connection
    $conn->close();
}
}

?>

Back to Directory=ceiIENDB`