pspfreak101 Posted October 19, 2008 Share Posted October 19, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/129116-news-delete-problem/ Share on other sites More sharing options...
.josh Posted October 19, 2008 Share Posted October 19, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/129116-news-delete-problem/#findComment-669369 Share on other sites More sharing options...
pspfreak101 Posted October 19, 2008 Author Share Posted October 19, 2008 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/129116-news-delete-problem/#findComment-669377 Share on other sites More sharing options...
Andy17 Posted October 19, 2008 Share Posted October 19, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/129116-news-delete-problem/#findComment-669380 Share on other sites More sharing options...
pspfreak101 Posted October 19, 2008 Author Share Posted October 19, 2008 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>"); } } } Quote Link to comment https://forums.phpfreaks.com/topic/129116-news-delete-problem/#findComment-669420 Share on other sites More sharing options...
.josh Posted October 19, 2008 Share Posted October 19, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/129116-news-delete-problem/#findComment-669452 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.