Record Deletion script only working some of the time

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mdmartiny1977
Forum Newbie
Posts: 16
Joined: Fri Jan 14, 2011 12:05 am
Location: Michigan, USA
Contact:

Record Deletion script only working some of the time

Post by mdmartiny1977 »

Hello Everyone I am in the process of creating a small CMS system for someone. My problem is that I am still in the process of learning PHP and MySql databases.

I am in the process of creating a deletion script for the CMS. Basically what I am trying to do is make it a three step process.

Pick the file to delete --> Verify it is the right file to delete --> Finally Delete the file

I have written the first two steps and have debugged them to the point of them working like I want them to for now. The third step is a hit and miss. Sometimes it deletes the file like it should and other times it does not. I am not sure what I am doing wrong.

This is the code for my show_modify2.php

Code: Select all

<?php

if (!$_POST[id]) {
	header ("LOCATION: pick_modify2.php");
	exit;
} else {
   //session start
   session_start();
}

if ($_SESSION[valid] != "yes") {
	header ("Location: admin_menu.php");
}

include('includes/connection.php');

//build and issue query
$sql = "SELECT * FROM $table WHERE id = '$_POST[id]'";
$result = mysql_query($sql, $connection) or die(mysql_error());

while ($row = mysql_fetch_array($result)) {
	$title = $row['title'];
	$year = $row['year'];
	$make = $row['make'];
	$model = $row['model'];
	$descript = $row['descript'];
}

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Add Classified Ad</title>
</head>
<body>
<h2><em>Delete ad from Database</em></h2>
<h3>Ad being deleted <?php echo "$title"; ?></h3>
<form method="POST" action="do_delete.php" />
<input type="hidden" name="id" value="<?php echo "$_POST[id]"; ?>" />
<input type="hidden" name="title" value="<?php echo "$title"; ?>" />
<p> <strong>Title:</strong> <?php echo "$title"; ?>
   </p>
   <p> <strong>Year:</strong> <?php echo "$year"; ?>
   </p>
   <p> <strong>Make:</strong> <?php echo "$make"; ?>
   </p>
   <p> <strong>Model:</strong> <?php echo "$model"; ?>
   </p>
   <p> <strong>Description:</strong> <?php echo "$descript"; ?>
   </p>
   <p>
      <input type="submit" name="submit" id="name" value="Delete Record" />
   </p>
</form>
<p><a href="admin_menu.php">Return to Administration Menu</a></p>
</body>
</html>

This is the code for my do_delete.php

Code: Select all

<?php

if (!$_POST[id]) {
	header ("LOCATION: pick_modify2.php");
	exit;
} else {
   //session start
   session_start();
}

if ($_SESSION[valid] != "yes") {
	header ("Location: admin_menu.php");
}

include('includes/connection.php');

//build and issue query
$sql = "DELETE FROM $table WHERE id = '$_POST[id]'";
$result = mysql_query($sql, $connection) or die(mysql_error());

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<h1>Ad has been deleted</h1>
<h2><em>Ad <?php echo "$_POST[title]"; ?> has been deleted from the <?php echo "$table"; ?> table</em></h2>
<p><a href="pick_modify2.php">Delete another posting</a></p>
<p><a href="admin_menu.php">Administration Menu</a></p>
</body>
</html>
If someone could point me in the right direction I would very much appreciate it
mdmartiny1977
Forum Newbie
Posts: 16
Joined: Fri Jan 14, 2011 12:05 am
Location: Michigan, USA
Contact:

Re: Record Deletion script only working some of the time

Post by mdmartiny1977 »

Oh I forgot to say that when I click on the delete ad button. It sends me back to the pick_modify2.php file
Post Reply