I have a page that shows gigs from database. First load only shows the title of each entry, and a button to show the full details, and a button to delete (not yet utilized)
I am having trouble passing on the ID value for each entry of my foreach loop. It always passes on the ID number of the last entry, no matter which one I click. So I always see the details of second gig, even if I click the first one. (I just have two gigs in the database for now)
Any suggestions how to pass on the ID of the one I click the SHOW button on?
This is my code
require_once "gigPDO.php";
//Show button is pressed
if (isset ( $_POST ["show"])) {
$id = $_POST ["id"];
//$id = 5;
try {
$dbase = new gigPDO();
$result = $dbase->searchGig($id);
//print_r($result);
foreach($result as $gig){
print("<p>Title: " . $gig->getTitle());
print ("<br>Venue: " . $gig->getVenue());
print ("<br>Date: " . $gig->getDate());
print ("<br>Time: " . $gig->getTime());
print ("<br>Country: " . $gig->getCountry());
print ("<br>Address: " . $gig->getAddress());
print ("<br>Postcode: " . $gig->getPostcode());
print ("<br>City: " . $gig->getCity());
print("<br>Description: " . $gig->getDescription() . "</p>");
echo "<br />";
unset($_POST ["show"]);
echo "<a href='searchGigs.php'>Back to list</a>";
exit();
}
exit ();
} catch ( Exception $error ) {
print("<p>Error: " . $error->getMessage ());
exit ();
}
}
//First load, shows all gigs
try {
$dbase = new gigPDO();
$result = $dbase->allGigs();
foreach($result as $gig){
print("<p>". $gig->getTitle(). "<p>");
print ("<input type='hidden' name='id' value='".$gig->getId() ."'>");
print('<input type="submit" name="show" class="next show-button" value="Show" />');
print(' <input type="submit" name="delete" class="next show-button" value="Delete" />');
echo "<br />";
echo "<br />";
}
if ($dbase->getRows() == 0){
print("There are no gigs in the database yet");
}else{
print("<p>Total " . $dbase->getRows() . " gigs</p>");
}
} catch ( Exception $error ) {
print("<p>Error: " . $error->getMessage ());
}