I have a database table Library
and I have fetched image src
from the table and gave the name of the image tag as id
from the table as name=".$idRow."
.
So what i want to do is that when the user clicks on an image id of the image from the table should be passed in the name of that image tag, which is successfully done.
But when i pass that id through a variable using session ($_SESSION['sessionBookId']=$idRow;
) to another PHP
file only the last id of the book is passed through that variable.
I want to pass the id of the image clicked but only the last id is passed. Is there a solution?
<?php
$sqlSelectImage = "SELECT * FROM Library WHERE 1";
$queryExec = mysqli_query($link, $sqlSelectImage);
while ($rs = mysqli_fetch_object($queryExec)) {
$idRow=stripcslashes($rs->id);
?>
<tr>
//image tag
<td align="center">
<?php
echo "<a href=".'book-view.php'." name=".$idRow.">";
$_SESSION['sessionBookId']=$idRow;
?>
<img src="<?php echo stripcslashes($rs->book_url); ?>" alt="" width="100" height="100" />
<?php echo"</a>" ?>
</td>
<td align="center">
<form action="" method="POST"><input type="submit" value="buy" name="bookView"/>
</form>
</td>
</tr>
<?php
if (isset($_POST['bookView'])) {
header("Location:book-view.php");
exit();
}
?>