hey guys, i have created a page called prod_det.php. the page displays the details of the product. below is the code. but it is not working. error message being received when i click the details button is Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean

<?php
    session_start();
    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Product</title>
    <link href="CSS/product.css" rel="stylesheet" type="text/css" />
    </head>

    <body>

    <?php 

    //Create the connection and select the DB 
    include('db_connect.php'); 

    // Select records from the DB 

    $query = "SELECT p.prod_name, p.prod_photo, pr.prod_price, pr.prod_desc, pr.prod_brand, pr.prod_w_c
              FROM tblproduct p
              INNER JOIN tblretprod pr ON p.prod_id = pr.prod_id"; 
    $result = mysql_query($query); 

    // Display records from the table ?>

    <?php while ($row = mysql_fetch_array($result)): ?>

    <div class="prod_box_big">
         <div class="top_prod_box_big"></div>
            <div class="center_prod_box_big">            

                 <div class="product_img_big"><?= '<img height="100" width="100" src="Images/Products/'.$row['prod_photo'].'"/>'; ?>
                   <div class="thumbs"><?= $row['prod_desc']; ?></div>
              </div>
                     <div class="details_big_box">
                         <div class="product_title_big"><?= $row['prod_name']; ?></div>
                         <div class="specifications">
                            Brand: <span class="blue"><?= $row['prod_brand']; ?></span><br />

                            Quantity: <span class="blue"><?= $row['prod_w_c']; ?></span><br />

                            Price include <span class="blue">TVA</span><br />
                         </div>
                         <div class="prod_price_big"><span class="reduce"><?= $row['prod_price']; ?>   </span> <span   class="price">%promo%</span></div>

                         <a href="#" class="addtocart">add to fav</a>
                         <a href="#" class="compare">compare</a>
                     </div>                        
            </div>
            <div class="bottom_prod_box_big"></div>                                
    </div>
    <?php endwhile; ?> 

    </body>
    </html>

Dani AI

Generated

The reason you see every product is that prod_det.php always runs a SELECT with no WHERE clause and then loops all rows. As you noted in Post #2, fixing the SELECT error was step one; the next step is to pass the clicked product’s id to prod_det.php and filter the query so you fetch just that row.

Minimal wiring from your product list (each button must carry the product id). This also opens a small popup with only the browser’s default chrome and your own Close button inside:

<a href="prod_det.php?id=<?= (int)$row['prod_id'] ?>"
   onclick="window.open(this.href,'prod',
    'width=640,height=480,menubar=0,toolbar=0,location=0,status=0,scrollbars=1');
    return false;">
  Details
</a>

In prod_det.php, validate the id and parameterize the query so you return one product. Example with PDO (recommended; mysql_* is obsolete and removed in PHP 7+):

$id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
if (!$id) { http_response_code(400); exit('Invalid product id'); }

$stmt = $pdo->prepare(
  'SELECT p.prod_name, p.prod_photo, pr.prod_price, pr.prod_desc, pr.prod_brand, pr.prod_w_c
   FROM tblproduct p
   JOIN tblretprod pr ON p.prod_id = pr.prod_id
   WHERE p.prod_id = ? LIMIT 1'
);
$stmt->execute([$id]);
$row = $stmt->fetch(PDO::FETCH_ASSOC) ?: (http_response_code(404) || exit('Product not found'));

Add a close control inside the popup page:

<button type="button" onclick="window.close()">Close</button>

Notes:

  • window.close() will only work if the page was opened via window.open() (as above).
  • Some window features (toolbar, location, etc.) are browser-controlled and may be ignored; if popup blockers are an issue, consider a modal dialog on the same page that fetches prod_det.php?id=... via AJAX.

Oops my mistake...i found the error...sorry guys

error was in the select statement

now the issue is that there is a product details button for each product display. when i click on my product details button, details of all products are displayed and not the details of the product i clicked. Any help in solving that please?

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.