Reputation: 306
I have a HTML file that is echoing out looped pending friend requests as follows:
// pending friend requests
$sql = $conn->prepare("Select * FROM Friends WHERE UserID = '$userID' AND Friends = 'p'");
$sql->execute();
$count = $sql->rowCount();
if($count > 0) { ?>
<form action="profile.php" method="POST">
<?php foreach($sql as $result) { ?>
<input type="text" value="<?php echo $result['FriendName'] ?>" name="result" readonly/>
<button type="submit" name="accept">Connect</button><button type="submit" name="decline">Decline</button>
<br />
<?php }
echo "</form>";
}
It loops out the options fine, however, when I click submit on say the 2nd or 3rd looped option it submits the 1st looped option. I am doing something similar on another page and this seems to be working it just seems to be causing an issue on this page, would anyone be able to explain to me what might be causing this and any possible solutions?
Upvotes: 0
Views: 83
Reputation: 5094
Try this
<?php foreach($sql as $result) { ?>
<form action="profile.php" method="POST">
<input type="text" value="<?php echo $result['FriendName'] ?>" name="result" readonly/>
<button type="submit" name="accept">Connect</button><button type="submit" name="decline">Decline</button>
</form>
<?php } ?>
Upvotes: 1