How to separate 'foreach' between pages in php?
Im creating a comment system on my website, each product page has its own comments. The problem is that when I create a message it appears on all product pages. In products table I have an id column for each product, if that helps. product.php  <?php include 'includes/session.php'; ?> <?php $conn = $pdo->open(); $slug = $_GET['product']; try{ $stmt = $conn->prepare("SELECT *, products.name AS prodname, category.name AS catname, products.id AS prodid FROM products LEFT JOIN category ON category.id=products.category_id WHERE slug = :slug"); $stmt->execute(['slug' => $slug]); $product = $stmt->fetch(); } catch(PDOException $e){ echo "There is some problem in connection: " . 'images/'.$product['photo'] : 'images/noimage.jpg'; ?>" width="100%" class="zoom" data-magnify-src="images/large-<?php echo $product['photo']; ?>"> <br><br> <form class="form-inline" id="productForm"> <div class="form-group"> <div class="input-group col-sm-5"> <span class="input-group-btn"> <button type="button" id="minus" class="btn btn-default btn-flat btn-lg"><i class="fa fa-minus"></i></button> </span> <input type="text" name="quantity" id="quantity" class="form-control input-lg" value="1"> <span class="input-group-btn"> <button type="button" id="add" class="btn btn-default btn-flat btn-lg"><i class="fa fa-plus"></i> </button> </span> <input type="hidden" value="<?php echo $product['prodid']; ?>" name="id"> </div> <button type="submit" class="btn btn-primary btn-lg btn-flat"><i class="fa fa-shopping-cart"></i> Add to Cart</button> </div> </form> </div> <div class="col-sm-6"> <h1 class="page-header"><?php echo $product['prodname']; ?></h1> <h3><b>$ <?php echo number_format($product['price'], 2); ?></b></h3> <p><b>Category:</b> <a href="category.php?category=<?php echo $product['cat_slug']; ?>"><?php echo $product['catname']; ?></a></p> <p><b>Description:</b></p> <p><?php echo $product['description']; ?></p> </div> </div> <br> <?php include 'comment.php'; ?> <?php include 'comment_show.php'; ?> </div> <div class="col-sm-3"> <?php include 'includes/sidebar.php'; ?> </div> </div> </section> </div> </div> <?php $pdo->close(); ?> <?php include 'includes/footer.php'; ?> </div> <?php include 'includes/scripts.php'; ?> <script> $(function(){ $('#add').click(function(e){ e.preventDefault(); var quantity = $('#quantity').val(); quantity++; $('#quantity').val(quantity); }); $('#minus').click(function(e){ e.preventDefault(); var quantity = $('#quantity').val(); if(quantity > 1){ quantity--; } $('#quantity').val(quantity); }); }); </script> </body> </html>  comment.php  <form action="" method="post"> <div class="form-group"> <textarea class="form-control" style="resize: none;" name="comment" id="" cols="30" rows="5" placeholder="Enter Message" required></textarea> <button type="sumbit" name="sumbitComment" class="btn btn-primary pull-right">Send Message</button> </div> </form> <?php if(isset($_POST['sumbitComment'])){ if(isset($_SESSION['user'])){ $conn = $pdo->open(); $comment = $_POST['comment']; $firstName = $user['firstname']; $userID = $user['id']; $sql = "INSERT INTO comments (comment, user_id, firstname) VALUES (:comment, :user_id, :firstname)"; $stmt = $conn->prepare($sql); $stmt->execute(['comment'=>$comment, 'user_id'=>$userID, 'firstname'=>$firstName]); $pdo->close(); } } ?>  comment_show.php