I am trying to pass an ID value from one page to withdraw data from an image database on another. I am trying to do this with session variables. If I hardcode the value for $id in the IEWIMAGE.PHP file, it works like a charm. I am trying to pass a session variable to the VIEWIMAGE.PHP file (shown below) from my td.php code snippet.
The output is fine (see printf stateement) but when it comes time to load the images from the viewimage.php reference, I get nothing.
I set a session variable $_SESSION['imageid'] within the "while" loop and unset it outside the loop.
td.php
while($row = mysqli_fetch_array($result,MYSQLI_BOTH))
{
$imagequery = " SELECT id FROM upload where userid = '$row[8]'";
$iqresult = mysqli_query($connection, $imagequery) or die('Error, QQuery failed');
$resultrow = mysqli_fetch_array($iqresult, MYSQLI_BOTH);
$_SESSION['imageid'] = $resultrow['id'];
$shorty=$_SESSION['imageid'];
printf("<img src=\"./viewimage.php?id=%s\" class=\"w100 b1s000\" />", $shorty);
echo" </a>";
VIEWIMAGE.PHP
<?php
session_start();
include("./login_data.txt");
$id=$_SESSION['imageid'];
if($id) {
$connection; //defined in login_data.txt
@mysqli_select_db($connection, 'upload');
$image=stripslashes($_REQUEST[id]);
$query = "select content, type from upload where id=$id";
$result = @mysqli_query($connection, $query) or exit("Error");
while ($row=mysqli_fetch_row($result)){
$content=$row[0];
$type=$row[1];
}
Header( "Content-type: $type");
echo $content;
mysqli_free_result($result);
};
?>