0

I am trying to send the product Id of the specific productId via sessions using php enter image description here Like When I click One of these I want to pass the Specific Product Id to my Next Page enter image description here So that I can Display The Data.

<?php
$sql = "SELECT * FROM products ORDER BY RAND() LIMIT 4" ;
$result= mysqli_query($conn,$sql);
while($row = mysqli_fetch_assoc($result)): ?>
<?php                                                   

$productId =$row['productId'];
$subCatId = $row['subCatId'] ;
$_SESSION['productId'] = $productId;?> //I TRIED THIS WAY BUT SINCE IT IS ON LOOP THIS SETS THE SESSION VARIABLE TO THE PRODUCT THAT IS DISPLAYED AT THE LAST
<?php
$sql = "SELECT * FROM pictures WHERE productId = $productId ";
$results= mysqli_query($conn,$sql);
if($rows = mysqli_fetch_assoc($results)): ?>
<?php $raw_url = $rows['pic'];
$urli = "uploads/".$raw_url;
<?php endif ?>

I am new to PHP and also have little knowledge on JS. Please Suggest what should I learn to solve this. Thank you!

  • 2
    Please don't post images of your code, just post your code. If we need to copy/paste it to replicate the behavior, you're making life extremely difficult for us. – rickdenhaan Oct 02 '17 at 18:21
  • Your `unset($_SESSION['productId'])` immediately after `$_SESSION['productId'] = $productId` instantly deletes the product id from the session right after you set it. Remove the `unset()` and you should be able to echo it. – rickdenhaan Oct 02 '17 at 18:24
  • You can do that with 1 query. Look into `join`s. You also need to start the session, and should get in the habit of parameterizing your queries. – chris85 Oct 02 '17 at 18:24
  • If you `unset` `$_SESSION['productId]` your destroy this variable so that's why you obtain such a message. – Tomasz W. Oct 02 '17 at 18:27
  • @TomaszW. Yeah That Worked Thanks But I am Having an Issue Here ` – Gaurab Panthee Oct 02 '17 at 18:32

0 Answers0