Im trying to pass a session variable $_SESSION['id'] form one page to another. But in the page im trying to pass it to I get this error Undefined index id
The pages are in different dirs but in the same parent dir obviously, would this have anything to do with it?
This is the first file
session_start();
include 'connect.php';
if(isset($_POST['category'])){
// cast the category to integer (just a little bit of basic security)
$cat = (int) $_POST['category'];
$q = "SELECT * FROM products WHERE cat=$cat AND status = 1 ORDER BY id DESC";
$result = $link->query($q);
// this will be the string that you will return into the product-data div
$returnHtml = '';
}
else if(isset($_POST['subcategory'])){
// cast the category to integer (just a little bit of basic security)
$subcat = (int) $_POST['subcategory'];
$q = "SELECT * FROM products WHERE subcat=$subcat AND status =1 ORDER BY id DESC";
$result = $link->query($q);
// this will be the string that you will return into the product-data div
$returnHtml = '';
}
// construct the html to return
while($row = mysqli_fetch_array($result)) {
$returnHtml .= "<div class='product'>";
$returnHtml .= "<a href='products.php' target='_blank''>";
$returnHtml .= "<img class='nailthumb-container'";
$returnHtml .= "src='{$row['image']}' ";;
$returnHtml .= "alt='{$row['name']}' ";
$returnHtml .= "title='{$row['name']}' />";
$returnHtml .= "</a>";
$returnHtml .= "<span class='productname1'>{$row['name']}</span>";
$returnHtml .= "<br />";
$returnHtml .= "<br />";
$returnHtml .= "<span class='productprice1'>£ {$row['price']}</span>";
$returnHtml .= "</div>";
$_SESSION['id']=$row['id'];
}
// display the html (you actually return it this way)
echo $returnHtml;
This is the second
<?php session_start(); ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<div class="productconainer">
<?php
$id = "SELECT * FROM products WHERE id = '".$_SESSION['id']."'";
$result = $link->query($id);
while($row = mysqli_fetch_array($result)) {
echo $row['image'];
}
?>
</body>
</html>