html - Delete data from database using php and sql
Solution:
From the question and comments, and a glance at your code it sounds like you probably actually need two pieces of data to be submitted to the server when your button is clicked:
The action which should be undertaken in response to the request (i.e. unfriending)
The ID of the person being unfriended
To achieve that you can add some hidden fields to your form. These are invisible to the user but will be available to PHP in the $_POST
data when the form is submitted.
Something like this:
<form action="friendlist.php" method= "POST">
<input type="hidden" name="unfriend_id" value="<?=$friend_id_got ?>" />
<input type="hidden" name="action" value="unfriend" />
<button id="add-friend-btn" type="submit" name= "submit">Unfriend</button>
</form>
Answer
Solution:
Following on from the comment from @ADyson:
<form action="friendlist.php" method= "POST">
<input type="hidden" name="cancel_id" value="<?=$friend_id_got ?>" />
<button id="add-friend-btn" type="submit" name="submit">Unfriend</button>
</form>
By including a hidden field in the form, you're able to store more information.
You can see that I'm storing the ID of the friend you're unfriending in the value of the hidden field, so when the form is submitted (the button is clicked) you'll have access to "cancel_id" in the POST data, which will obviously contain the ID of the friend to unfriend.
Source