Freddy Freddy - 1 year ago 32
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
. The idea is that by using
I can get
(from the first
), and
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
table. My
table has the following structure:


So the only way I can delete the users posts is by
, which I am trying to
from the second

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.
echo's the value of
which is correct, it is the
of the user logged in. But nothing is being echoed for
which is making me think that I cannot use
for a value assigned to another anchor link?

Answer Source

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