I'm trying to create a liking function for my image site so users can like or dislike images... They start off on the homepage where they can see a thumbnail of the image. Once they click a thumbnail, they're brought to viewimage.php to view the full size. It's there that they can like.
The issue is, the associated $imgid is not being updated, so once you load viewimage.php, I'm stuck with that $imgid, and consequently the associated total likes.
homepage.php: contains small thumbnails of each full-sized image. As you can see, if they click on a thumbnail, one of the parameters sent to viewimage.php is $row['id'], which I get with a $_GET.
while ($row = $catResult->fetch_assoc()) {
...
echo '<a href=".?action=viewimage&site='.$site. '&id=' . $row['id'] .'"><img src ... /></a>'
...
}
viewimage.php After the click on a thumbnail, they're show the full size image on viewimage.php. Users can navigate images by pressing left and right arrow... This would modify javascript variable "imgIndex", which is set to the server side $imgid.
$imgid = $_GET['id'];
include './scripts/keyinput.php';
$newID = $_POST['_postID'];
echo $newID;
keyinput.php Javascript that's included in viewimage.php. In this code snippet, when the user presses the right arrow, the $post should alter the server side $imgid, but it's not.
<script type="text/javascript">
var imgArray = [<?php echo implode(',', getImages($site)) ?>];
var imgIndex = <?php echo $imgid ?>;
$(document).ready(function() {
$(document).keydown(function (e) {
if (key == rightarrow) {
imgIndex++;
$.post('./templates/viewimage.php', { _postID : imgIndex });
}
...
});
</script>
<?php
function getImages($siteParam) {
include 'dbconnect.php';
if ($siteParam == 'artwork') {
$table = "artwork";
}
else {
$table = "comics";
}
$catResult = $mysqli->query("SELECT id, title, path, thumb, views, catidFK FROM $table");
$img = array();
while($row = $catResult->fetch_assoc())
{
$img[] = "'" . $row['path'] . "'";
}
return $img;
}
?>
It gives me an error: Undefined index: _postID in C:\wamp\www\HTwS\templates\viewimage.php on line 16
Why can't the $.post function on keyinput.php send the updated imgid back to viewimage.php?
Thank you!