I realize there have been other answers to similar questions before, however I'm trying to make a collection of links unique in a table and can't seem to get the id of the tag to post to a php page.
See below:
echo("<p>To reserve a book, click the Book Title.</p>");
echo "<table class='formfield' border='1'>
<tr>
<th>Book ID</th>
<th>ISBN</th>
<th>Book Title</th>
<th>Author</th>
<th>Edition</th>
<th>Year</th>
<th>Category</th>
<th>Reserved</th>
</tr>";
$lnkCount = 0;
while($row = mysqli_fetch_array($sql)) {
$lnkCount++;
echo "<tr>";
echo "<td>" . $row['bookID'] . "</td>";
echo "<td>" . $row['ISBN'] . "</td>";
echo "<td><a class='anchor' id='$lnkCount' href='reservation.php'>" . $row['BookTitle'] . "</a></td>";
echo "<td>" . $row['Author'] . "</td>";
echo "<td>" . $row['Edition'] . "</td>";
echo "<td>" . $row['Year'] . "</td>";
echo "<td>" . $row['CategoryDept'] . "</td>";
echo "<td>" . ($row['Reserved'] ? 'Yes' : 'No') . "</td>";
/*echo "<td><input id='$lnkCount' type='button' value='Reserve Now' onClick='post();'></td>";*/ // display yes/no rather than boolean equivalent...
}
echo "</table>";
Then my jQuery:
<script lang="JavaScript" type="text/javascript">
$(".anchor").click(function() {
var clkID = $(this).attr("id");
alert(clkID);
$.post('reservation.php'), {clkID:postid}, function(){/*do something*/};
});
</script>
And finally my php page, which isn't really relevant but I'll post for clarity in my question.
$id = $_POST['postid'];
echo("<p>Value detected was: $id</p>"); // this is just to test...
Now when I click on one of the links, the page alerts with the correct id of the link I clicked. But then when it connects to the php page (reservations.php) it gives me the following error:
Notice: Undefined index: postid in C:\xampp\htdocs\webDevProj\reservation.php on line 41 Value detected was:
As I'm sure >=1 of you will know I'm not very experienced with jQuery - so if you understand my problem and think there's a much easier way to do it I would really appreciate your input!
p.s. it's for a college assignment :)
EDIT #1 -- Don't see how this question has any relevance to the one reported as answered. It involves jQuery .post methods. The "solution" provided gives various definitions to what "undefined index" means in regards to php but does still not have any significance on my question.
EDIT #2 -- So I changed the variable and the key around in my JS code without any change. I was hopeful for that split second lol - guess I'll keep looking...