My database table (related) contains 3 columns:
- related_id
- article_id
- object_id
This is a table that tracks the relationship between articles and objects. I stripped the code. Now it just contains a delete button (x). If someone clicked this button, I want the user to be redirected if(isset($_POST['deleteRelated']))to receive the message "Are you sure", etc. But the hidden identifier is not passed correctly. Last related_idin table 29 . When I try to revoke a hidden id, I just get 29 for each delete button (x).
The full version of the code below gives me a table with the title of the article, the name of the object, and the delete button (x). Since the submit button cannot pass the value, I need a hidden value. But when I transfer it by pressing the delete button (x), I get 29 every time.
the code
if(isset($_POST['deleteRelated'])) {
echo $_POST['hidden-id'];
else {
echo '
<form method="post">';
$stmt = $db->prepare("SELECT * FROM Related");
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $related) {
echo '
<input type="hidden" name="hidden-id" value="' . $related['related_id'] . '">
<input type="submit" name="deleteRelated" value="x">';
}
echo '
</form>';
}
If I print:
<input type="submit" name="deleteRelated" value="' . $related['related_id'] . '">
It will display the correct value from the database instead of x for the delete / submit button. But when I click the delete / submit button, I just get the last one related_id, which is 29 .
Can someone solve this problem? Shouldn't it be that hard?
Treps source
share