AibZilla Posted June 15, 2012 Share Posted June 15, 2012 Hi, I have created an application where a user can create, delete, and update lists. These functions are working fine except I want to echo a message that tells the user once hes deleted a a message that his delete was successful. I've already made some code but nothing seems to be echoing out.. here it is. delete-list.php <?php require('includes/list-brains.php'); if (isset($_GET["listid"])) { $listMonster = new Lists(); $deleteResult = $listMonster->DeleteList($_GET["listid"]); if ($deleteResult) { // return to list page with success message header("Location: /index.php?message=Deleted List"); } else { // return to list page with failure message header("Location: /index.php?message=Sorry No Dice"); } } else { header('Location: /'); } ?> Here is list-brains.php public function DeleteList($listId) { $sql2 ="DELETE FROM `toitdoit`.`lists` WHERE ListId = ".$listId; $result2 = mysql_query($sql2); $DeleteSuccessful = mysql_affected_rows(); if ($DeleteSuccessful) { $sql1 = "DELETE FROM `toitdoit`.`items` WHERE ListId = ".$listId; $result1 = mysql_query($sql1); } return $DeleteSuccessful; } how can i have the message be echoed to my index page when the list is deleted?? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted June 15, 2012 Share Posted June 15, 2012 You don't appear to be echoing anything at all in that code . . . Quote Link to comment Share on other sites More sharing options...
AibZilla Posted June 15, 2012 Author Share Posted June 15, 2012 How can I grab the code I already have and make it echo in my index.php after a list is deleted successfully? Quote Link to comment Share on other sites More sharing options...
AibZilla Posted June 15, 2012 Author Share Posted June 15, 2012 *When the delete button is pressed the list does delete but does not show the message delete successful, this is what i'm trying to do is recieve the message. Anyone know what i'm doing wrong? Quote Link to comment Share on other sites More sharing options...
Mahngiel Posted June 15, 2012 Share Posted June 15, 2012 in your header, you'll need to pass another parameter to which you'll need a conditional check for it's existence. if that param exists, then you can create an element and make it appear Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 15, 2012 Share Posted June 15, 2012 You are calling a function DeleteList() to perform the delete process. That function is returning a value $DeleteSuccessful which only tells you if the first delete 'lists' is successful. It doesn't tell you if the second delete 'items' is successful. You then use that return value to do one of two redirects if ($deleteResult) { // return to list page with success message header("Location: /index.php?message=Deleted List"); } else { // return to list page with failure message header("Location: /index.php?message=Sorry No Dice"); } In the success scenario, you are redirecting the user to index.php with the optional URL parameter 'message' set to 'Deleted List'. First of all I would change that value, remove the space, or urlencode() the value. For the sake of this argument I will assume the value is changed to 'DeletedList'. So, all you need to do in your index.php page is see if that url parameter is set and has that value. if(isset($_GET['message']) && $_GET['message']=='DeleteList') { echo "The list was successfully deleted."; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.