Jump to content

Delete pages not working


doctortim

Recommended Posts

Hi

 

I am creating my two pages for removing records (articles) from my blog databases. These pages are delete.php and confirm_delete.php

 

I can't really find why the code is getting rid of them from the database.

 

Here is my php code in the confirm delete page...

 

<?php
include_once("include/connect_sql.inc.php");

$thisArticle_id = $_POST['article_id'];
$sql = "SELECT * FROM blogprofessional
		WHERE article_id = '".$thisArticle_id."'";
$result = mysql_query($sql);
$numberOfRows = mysql_num_rows($result);

if ($numberOfRows==0) {  
echo 'Sorry. No records found !!';
}
else if ($numberOfRows>0) {

$i=0;
$article_id = mysql_result($result,$i,"article_id");
$issue_no = mysql_result($result,$i,"issue_no");
$issue_date = mysql_result($result,$i,"issue_date");
$focus = mysql_result($result,$i,"focus");
$toc = mysql_result($result,$i,"toc");
$article = mysql_result($result,$i,"article");
  }
?>

 

and the confirm delete button/form is as follows:

 

<tr><form name="customersEnterForm" method="POST" action="pro_blog_delete.php">
          <td width="609"><input type="hidden" name="thisArticle_idField" value="<? echo $thisArticle_id; ?>" /></td>
          <td width="215"><input type="submit" name="submitConfirmDeleteCustomersForm" value="Delete from Blog Archive" /></td>
          <td width="85"><input type="button" name="cancel" value="Back" onclick="javascript:history.back();" /></td></form>
        </tr>

 

now finally when the button is clicked and redirection to the delete page occurs this is the code that should process:

 

<?php
include_once("include/connect_sql.inc.php");

// Retreiving Form Elements from Form
$thisArticle_id = addslashes($_POST['thisArticle_idField']);


$sql = "DELETE FROM blogprofessional
		WHERE article_id = '$thisArticle_id'";
$result = mysql_query($sql);

?>

 

When I check in phpmyadmin the record has not been deleted.

 

Please help, thank you very much.

Link to comment
Share on other sites

I looked at the page source and found this for my confirm delete form:

 

 

<tr>

<form name="customersEnterForm" method="POST" action="pro_blog_delete.php">

          <td width="609"><input type="hidden" name="thisArticle_idField" value="" /></td>

          <td width="215"><input type="submit" name="submitConfirmDeleteCustomersForm" value="Delete from Blog Archive" /></td>

          <td width="85"><input type="button" name="cancel" value="Back" onclick="javascript:history.back();" /></td>

</form>

</tr>

 

 

The value is not getting the article id echoed into it. Once again, the php to insert the article id is follows

 

<tr>
<form name="customersEnterForm" method="POST" action="pro_blog_delete.php">
          <td width="609"><input type="hidden" name="thisArticle_idField" value="<?php echo $article_id; ?>" /></td>
          <td width="215"><input type="submit" name="submitConfirmDeleteCustomersForm" value="Delete from Blog Archive" /></td>
          <td width="85"><input type="button" name="cancel" value="Back" onclick="javascript:history.back();" /></td>
</form>
</tr>

 

I am also getting the "Sorry,no records found" message from the top part of my confirm delete page, which once again comes from this code:

 

<?php
include_once("include/connect_sql.inc.php");

$thisArticle_id = $_POST['article_id'];
$sql = "SELECT * FROM blogprofessional
		WHERE article_id = '".$thisArticle_id."'";
$result = mysql_query($sql);
$numberOfRows = mysql_num_rows($result);

if ($numberOfRows==0) {  
echo 'Sorry. No records found !!';
}
else if ($numberOfRows>0) {

$i=0;
$article_id = mysql_result($result,$i,"article_id");
$issue_no = mysql_result($result,$i,"issue_no");
$issue_date = mysql_result($result,$i,"issue_date");
$focus = mysql_result($result,$i,"focus");
$toc = mysql_result($result,$i,"toc");
$article = mysql_result($result,$i,"article");
  }
?>

 

Im stumped

 

By the way this is the results of the error for the delete query

 

Delete query: DELETE FROM blogprofessional WHERE article_id = ''Rows affected: 0

 

therefore the variable $thisArticle_id is not getting its value

 

// Retreiving Form Elements from Form
$thisArticle_id = addslashes($_POST['thisArticle_idField']);

 

The argument for post is from 'name' in the confirm delete button.

 

Though still doesn't appear to explain why the "no records" message appears on the confirm delete page.

Link to comment
Share on other sites

Where should this line get the ID from?

 

<td width="609"><input type="hidden" name="thisArticle_idField" value="<?php echo $article_id; ?>" /></td>

 

You are echoing $article_id into the form, yet nothing is setting $article_id to the actual row id.

Link to comment
Share on other sites

yeah on my article listings page, each entry has a "delete" link next to it like this

 

 

<a href="pro_blog_confirm_delete.php?article_id=<?php echo $row['article_id']; ?>">Delete Record</a>

 

 

when you hover over the delete link the correct article id shows up in the bottom of the browser so I know that works.

 

Then you link through to the confirm delete page where the header is as so:

 

<?php
include_once("include/connect_sql.inc.php");

$thisArticle_id = $_POST['article_id'];
$sql = "SELECT * FROM blogprofessional
		WHERE article_id = '".$thisArticle_id."'";
$result = mysql_query($sql);

$numberOfRows = mysql_num_rows($result);

if ($numberOfRows==0) {  
echo 'Sorry. No records found !!';
}
else if ($numberOfRows>0) {

$i=0;
$article_id = mysql_result($result,$i,"article_id");
$issue_no = mysql_result($result,$i,"issue_no");
$issue_date = mysql_result($result,$i,"issue_date");
$focus = mysql_result($result,$i,"focus");
$toc = mysql_result($result,$i,"toc");
$article = mysql_result($result,$i,"article");
  }
?>

 

thats where it is getting the id from, isn't this correct??!?

Link to comment
Share on other sites

Try this, i think it is what you were trying to do.

 

In here i am assuming that the article id is numeric and that the article id will be passed through the url, example: http://www.yourdomain.com/delete.php?article_id=1. all you need to worry about is making sure that ?article_id= is after your url. this combines all of your files into one to make it easier to maintain

 

<?php
include_once("include/connect_sql.inc.php");
if($_GET['article_id']) {
	if(is_numeric($_GET['article_id'])) {
		$article_id = $_GET['article_id'];
		$article_query = mysql_query("SELECT * FROM blogprofessional WHERE article_id='" . $article_id . "'");
		$article_num = mysql_num_rows($article_query);
		if($numberOfRows > 0) {
			$article_array = mysql_fetch_array($article_query);
			$article_issue_num = $article_array['issue_no'];
			$article_issue_date = $article_array['issue_date'];
			$article_focus = $article_array['focus'];
			$article_toc = $article_array['toc'];
			$article = $article_array['article'];
			if($_POST['confirm']) {
				if(mysql_query("DELETE FROM blogprofessional WHERE article_id='" . $article_id . "'")) {
					print 'Blog deleted';
				}
				else {
					print 'Failed connectiong to the server. Please notify an admin with this error: ' . mysql_error();
				}
			}
			else {
				print '<form action=' . $_SERVER['PHP_SELF'] . '?article_id=' . $article_id . ' method=post>';
				print '<table>';
				print '<tr>';
				print '<td width="215"><input type=submit name=confirm value="Delete from Blog Archive" /></td>';
				print '<td width="85"><input type=button name=cancel value="Back" onclick="javascript:history.back();" /></td></form>';
				print '</tr>';
				print '</table>';
				print '</form>';
			}
		}
		else {
			print 'No articles found';
		}
	}
	else {
		print 'No articles found';
	}
}
else {
	print 'No articles found';
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.