Jump to content

News Delete problem


pspfreak101

Recommended Posts

I'm trying to build my admin panel, so for the new I click on edit news and displays the current news but when I click on delete it does absolutely nothing. I've switched it around a few times and still doesn't work

 

//Delet news 
if (isset($deletenews)) { 
if ($row["admin"] == "1") {
  $sql = "DELETE FROM news " .
             "WHERE ID=$deletenews";
      if (mysql_query($sql)) {
        echo("<P>The news has been deleted.</P>");
      } else {
        echo("<P>Error deleting news: " .
             mysql_error() . "</P>");
      }
    }  
}

if (@$_GET['action'] == 'editn') {
if ($row["admin"] == "1") {

echo("<center<P>Current News</P></center>");
  
$result = mysql_query(
"SELECT ID, body FROM news");
    if (!$result) {
      echo("<P>Error performing query: " .
           mysql_error() . "</P>");
      exit();
    } 

while ( $row = mysql_fetch_array($result) ) {
      $newsid = $row["ID"];
      $newstext = $row["body"];
      echo("<P>$newstext " .
           "<A HREF='$PHP_SELF?deletenews=$newsid'>" .
           "Delete</A></P>");
    } 

}//end admin
}//end edit

Link to comment
Share on other sites

You have deletenews as a var to be passed in your url (the links generated in your while loop).  But you have

 

if (isset($deletenews)) {

 

is there somewhere before there that has something like this?

 

$deletenews = $_GET['deletenews'];

 

because vars passed through the url get put into the $_GET array.

Link to comment
Share on other sites

No I don't have anything like that even if I have it like this if ($_GET['deletenews']) { still doesn't work

 

heres my whole admin snipit 

 

/////////////////////////////////Admin\\\\\\\\\\\\\\\\\\\
if (@$_GET['action'] == 'admin') {

$loggedin = false;

if ($row["admin"] == "1") {

$loggedin = true;

} else {

echo "Please login to access the Administration Panel";

  }

}//end action

if ($loggedin == true) {

echo "Welcome <b>" . $_SESSION['username'] ." </b> the to Administration Panel";

echo "<li><a href=\"index.php?action=editd\">Edit Download Entries</a></li>\n";
echo "<li><a href=\"index.php?action=editm\">Edit Members</a></li>\n";
echo "<li><a href=\"index.php?action=editn\">Edit News</a></li>\n";
echo "<li><a href=\"index.php?action=submitn\">Submit News</a></li>\n";
echo "<li><a href=\"index.php?action=dapprove\">Approve Download Entries</a></li>\n";


} //end loggedin


if (@$_GET['action'] == 'dapprove') {

if ($row["admin"] == "1") {


$sql = "select count(approve) as totals from downloads group by approve";
$result = mysql_query($sql);
$unapproved = mysql_result($result, 0, 'totals');
$approved = mysql_result($result, 1, 'totals');

if(empty($unapproved)) {
$unapproved = 0;
}

echo "Their are ". $approved ."  approved entries<br>";
echo "". $unapproved ." waiting for approval<br>";

}//end 
}//End admin


//Delet news 
if (isset($deletenews)) { 
if ($row["admin"] == "1") {
  $sql = "DELETE FROM news " .
             "WHERE ID=$deletenews";
      if (mysql_query($sql)) {
        echo("<P>The news has been deleted.</P>");
      } else {
        echo("<P>Error deleting news: " .
             mysql_error() . "</P>");
      }
    }  
}

if (@$_GET['action'] == 'editn') {
if ($row["admin"] == "1") {

echo("<center<P>Current News</P></center>");
  
$result = mysql_query(
"SELECT ID, body FROM news");
    if (!$result) {
      echo("<P>Error performing query: " .
           mysql_error() . "</P>");
      exit();
    } 

while ( $row = mysql_fetch_array($result) ) {
      $newsid = $row["ID"];
      $newstext = $row["body"];
      echo("<P>$newstext " .
           "<A HREF='$PHP_SELF?deletenews=$newsid'>" .
           "Delete</A></P>");
    } 

}//end admin
}//end edit

///////Submit News\\\\\\\\\\\
if (@$_GET['action'] == 'submitn') {

if ($row["admin"] == "1") {


echo "<div align=\"center\" class=\"style1\">Submit News</div>\n";
echo "<form name=\"form1\" method=\"post\" action=\"index.php\">\n";
echo "Title:<input type=\"text\" name=\"title\" id=\"title\"><br />\n";
echo "Author: <b>" . $_SESSION['username'] . "</b> <br />\n";
echo "<label>Body\n";
echo "<textarea name=\"body\" id=\"body\" cols=\"50\" rows=\"8\" ></textarea></label>\n";
echo "<br />\n";
echo "<center><input type=\"Submit\" name=\"submitn\" id=\"submitn\" value=\"submit\"></center>\n";
echo "</form>\n";
  
   }
}

//News Submit
if (@$_POST["submitn"] ) {
// Check if a person has filled every form.
if(empty($_POST['title']) || empty($_POST['body'])) {
	echo "You have to fill in everything in the form."; 
                exit;
}// end check

$title = $_POST['title'];
$body = $_POST['body'];
$author = $_SESSION['username'];

$query = "INSERT INTO `news` (title, body, author, date) 
                      VALUES ('$title', '$body', '$author','date=now()')";
// Perform the SQL query on the database.
$result = mysql_query($query);
// If the query failed, display an error.
if(!$result) { 
                // The dot seperates PHP code and plain text.
	echo "Your query failed. " . mysql_error();
} else {
	// Display a success message!
	echo "Your news has been posted" . $_SESSION['username']  . " <a href=index.php> Click here to return</a>";
}

}//end submit

?>

Link to comment
Share on other sites

Try to insert some echoes inside like every if statement and see where it stops. This would help us as well, since your problem could be in the code you are not showing us. I didn't look that closely at your code; would appreciate if you could tell me when the problem occurs. Thank you.

Link to comment
Share on other sites

Well whats not happening is that if (@$_GET['deletenews'] == '$newsid') { is not matching up with the request so its not preforming the delete and just need to know exactly how to make it preform the query

 

heres my updated code

 

if (@$_GET['action'] == 'editn') {
if ($row["admin"] == "1") {

echo("<center<P>Current News</P></center>");
  
$result = mysql_query(
"SELECT ID, body FROM news");
    if (!$result) {
      echo("<P>Error performing query: " .
           mysql_error() . "</P>");
      exit();
    } 

while ( $row = mysql_fetch_array($result) ) {
      $newsid = $row["ID"];
      $newstext = $row["body"];
      echo("<P>$newstext " .
           "<A HREF='$PHP_SELF?deletenews=$newsid'>" .
           "Delete</A></P>");
    } 

}//end admin
}//end edit

//Delet news 
if (@$_GET['deletenews'] == '$newsid') {
if ($row["admin"] == "1") {
  $sql = "DELETE FROM news " .
             "WHERE ID=$deletenews";
      if (mysql_query($sql)) {
        echo("<P>The news has been deleted.</P>");
      } else {
        echo("<P>Error deleting news: " .
             mysql_error() . "</P>");
      }
    }  
}

 

 

Link to comment
Share on other sites

Okay no, you don't get it.  It's just like using posted variables from a form, but instead you are using $_GET instead of $_POST.  Your deletenews=$newsid is being assigned to $_GET['deletenews'] not $deletenews.  So you have to check for $_GET['deletenews'] and you have to use that in your query, or at least assign $_GET['deletenews'] to $deletenews before using $deletenews.  Look at this post I recently made for some other thread.  It gives a simple example of a delete link and how to check for it and delete a row in your database with it.

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.