Freddy Freddy - 7 months ago 9
SQL Question

Using $_GET for a value assigned to separate anchor link

I have the following two anchor links:

<a href='/inc/delete_user_and_remove_flagged.php?user_id=$u_id'> Remove User </a>
<a href="/inc/remove_flagged.php?id=$thought_id">Remove post flagged</a>


I am currently working in
delete_user_and_remove_flagged.php
. The idea is that by using
$_GET
I can get
user_id
(from the first
<a>
), and
delete
the account
where id='$user_id'
.

But I also want to remove all the posts of the user whose account is being delete from the
flagged_posts
table. My
flagged_posts
table has the following structure:

id
thought_id
flagged_by_id


So the only way I can delete the users posts is by
thought_id
, which I am trying to
$_GET
from the second
<a>
link.

Here is my current approach:

// 1. Close users account.
// 2. Delete all flagged posts relating to deleted user.

// 1.
$user_id = $_GET['user_id'];
$delete_query = mysqli_query ($connect, "UPDATE users SET closed = 'no' WHERE id = '$user_id' ");

// 2.
$post_id = $_GET['id'];
$del_query = mysqli_query ($connect, "DELETE FROM flagged_posts WHERE thought_id = '$post_id'");

//header ("Location: /admin_flagged.php");
echo $user_id. "" . $post_id;


As you can see, I am echoing the vars to see if it is obtaining the correct values.
$user_id
echo's the value of
9
which is correct, it is the
id
of the user logged in. But nothing is being echoed for
$post_id
which is making me think that I cannot use
$_GET
for a value assigned to another anchor link?

Answer

You can put more than on parameter on one anchor tag so you could do

<a href='/inc/delete_user_and_remove_flagged.php?user_id=$u_id&thought_id=$thought_id'> Remove User </a>
<a href="/inc/remove_flagged.php?id=$thought_id">Remove post flagged</a>

And pass both id's on the same Remove User click

This would generate a $_GET['user_id'] and a $_GET['thought_id'] from the same single click