-1

So, I am trying to redirect after I delete a user from the MySQL table. I have achieved this. The problem is that in the "delete-user.php" URL, I specify a "ID" to delete. For some reason, the "delete-user.php" page is blank, even when I try to put a redirect link.

Basically, the "ID" in the url is stopping me from clicking a redirect button to go back to the last page. By stopping I mean that the linked text is not showing up.

My code for delete-user.php is below.

<!DOCTYPE html>
<html lang="en">

<?php

$SQL = $odb->prepare("DELETE FROM users WHERE `ID` = :id");
$SQL->execute(array(':id' => $id));

?>

<a href="http://www.thisistheredirecturl.com">Go Back</a>

</html>

Keep in mind that the actual delete function works.

Thank you.

Edit: This is how the manage-users page looks. http://prntscr.com/7o6kno When you click on delete, it will redirect to the delete-user page and delete the user. (With the id parameter of the user) Unfortunately, I cannot get it to redirect back to the manage-users page.

Revolt
  • 1
  • 1
  • The php dies, the html lives on. The browser gets the html and redirects. So this always redirects the user. – Norbert van Nobelen Jul 03 '15 at 00:05
  • possible duplicate of [How Can I Display Static HTML After I've Used die() in a PHP Block?](http://stackoverflow.com/questions/307322/how-can-i-display-static-html-after-ive-used-die-in-a-php-block) – Mark Leiber Jul 03 '15 at 00:11
  • Why are you calling `die()`? – Mark Leiber Jul 03 '15 at 00:25
  • Thought adding die() would fix the problem. – Revolt Jul 03 '15 at 01:32
  • Are you saying that when you click the Delete button on your manage-users page, it loads delete-user.php, successfully deletes the user from your database, but does not display the "Go Back" link? How are you loading delete-user.php? Is it an ajax request? Can you show some of the code from manage-users? – Mark Leiber Jul 03 '15 at 02:13
  • http://pastebin.com/KiuWNpia Thank you – Revolt Jul 03 '15 at 02:53
  • After you click the Delete button, is your browser actually taking you to `delete-user.php?id=###` or is it dropping the id and taking you to `delete-user.php?`? (this is why I ask: http://stackoverflow.com/questions/1116019/submitting-a-get-form-with-query-string-params-and-hidden-params-disappear). Also, do you have display_errors enabled? – Mark Leiber Jul 03 '15 at 03:19
  • The browser is taking me to delete-user.php?id=###. I currently do not have display_errors enabled because I don't have access to the .ini file. – Revolt Jul 03 '15 at 18:34
  • You don't need access to the .ini file. See: http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display – Mark Leiber Jul 03 '15 at 23:28
  • Nothing shows up even when I added that. – Revolt Jul 05 '15 at 02:16
  • The code that you've shared so far is incomplete. Where is your form? If possible, show a complete example that can be reproduced. As it is, I had to guess at your code, and mine is working without any issues. When you get the blank page, is the record getting deleted from the database? – Mark Leiber Jul 06 '15 at 17:26

1 Answers1

0

Make it more simple, don't add a button to redirect you back to the page where you are deleting, just add a meta function to just refresh the page in your current page. EX: admin_site_delete_users.php, you can see here all the users and there is a delete id beside each and everyone of them, when you click it, it will call the delete-user.php, right? so in your delete-user.php just add a refresh meta with the admin_site_delete_users.php inside it so it will just refresh the page.

Jim Steven
  • 115
  • 10
  • I tried doing that. Nothing happens. I also tried using the "header" redirect, didn't work either. – Revolt Jul 03 '15 at 00:14
  • What do you mean by "nothing happens", from the comment that I gave above, I actually made it 2days ago so I can still remember how I did it that way, maybe you have some error in your script. – Jim Steven Jul 03 '15 at 00:16
  • Its a blank page and it doesn't refresh or redirect in anyway. – Revolt Jul 03 '15 at 01:30