Jump to content

Deleting a list and telling user Delete was successful!


AibZilla

Recommended Posts

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??

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.";
} 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.