marcus Posted December 5, 2006 Share Posted December 5, 2006 Fourth time with no help, again, I will try to post this.Problem: Comments will not delete.Situation: Administrative comment deletion. Administrators can delete comments, the comments will not delete.Code:[code]<? include('../header.php'); ?><?phpif($_COOKIE[admin]){ $action = $_GET[act]; $act = $_POST[act]; if($action == delete){ $NFin = "SELECT * FROM `news` WHERE `comments` =1"; $NFgo = mysql_query($NFin); $NFnu = mysql_numrows($NFgo); if($NFnu == 0){ echo "No active news"; }else { echo "<table border=0 cellspacing=2 cellpadding=1>"; echo "<form name=delcomfnews action='".$_SERVER[PHP_SELF]."' method=post>"; echo "<tr><td colspan=2 align=right><h3>Delete Comments - Step 1</h3>"; echo "<tr><td>"; echo "<select name=delcomnews>"; while ($row1 = mysql_fetch_array($NFgo, MYSQL_BOTH)){ echo "<option value=$row1[id]>$row1[title]</option>"; }; mysql_free_result($NFgo); echo "<td><input type=hidden name=act value=dels1><input type=submit value='Show Comments'>"; echo "</form>"; echo "</table>"; }; }else if($act == dels1){ $NFid = $_POST[delcomnews]; $NFin = "SELECT * FROM `comments` WHERE newsid ='$NFid'"; $NFgo = mysql_query($NFin) or die(mysql_error()); $NFnu = mysql_numrows($NFgo); if($NFnu == 0){ echo "There are no comments for news ID #$NFid"; }else { echo "<table border=0 cellspacing=2 cellpadding=1>"; echo "<tr><td colspan=2 align=right><h3>Delete Comments - Step 2</h3>"; while ($row1 = mysql_fetch_array($NFgo, MYSQL_BOTH)){ echo "<tr><td>Posted by: $row1[poster]<td>($row1[ip])"; echo "<tr><td colspan=2 align=left>$row1[message]"; echo "<form name=delcom action='".$_SERVER[PHP_SELF]."' method=post>"; echo "<input type=hidden name=act value=delcomgo>"; echo "<tr><td colspan=2 align=right><input type=hidden name=newid value=$NFid><input type=hidden name=comid value=$row1[id]><input type=submit value='Delect Comment #"."$row1[id]"."'>"; echo "</form>"; } mysql_free_result($NFgo); echo "</table>"; } if($act == delcomgo){ $comid = $_POST[comid]; $newid = $_POST[newid]; $DELcom = "DELETE FROM `comments` WHERE id =$comid"; $DELsql = mysql_query($DELcom) or die(mysql_error()); $sql1 = "SELECT camount FROM `news` WHERE id =$newid"; $sql2 = mysql_query($sql1); $sql3 = mysql_fetch_assoc($sql2); $sql4 = $sql3[camount]; $sql5 = "$sql4 - 1"; $sql6 = "UPDATE `news` SET camount ='$sql5' WHERE id=$newid"; $sql7 = mysql_query($sql6); echo "Comment ID #$comid has been deleted!"; }; }else if(!$act || !$action){ echo "<table border=0 cellspacing=3 cellpadding=2>"; echo "<tr><td colspan=2 align=right><h3>Comment Admin</h3>"; echo "<tr><td colspan=2 align=left><a href=comments.php?act=edit>Edit Comments</a>"; echo "<tr><td colspan=2 align=left><a href=comments.php?act=delete>Delete Comments</a>"; echo "</table>"; }; }else {echo "Bad auth";};?><? require('../footer.php'); ?>[/code] Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 5, 2006 Share Posted December 5, 2006 The else almost 1/2 way down from the top as no { after it. Other than that, you might want to learn to do some basic debugging. Quote Link to comment Share on other sites More sharing options...
marcus Posted December 6, 2006 Author Share Posted December 6, 2006 It's an else if.[code] }else if($act == dels1){[/code] Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted December 6, 2006 Share Posted December 6, 2006 [code=php:0]echo "<option value=$row1[id]>$row1[title]</option>";[/code]should be[code=php:0]echo "<option value={$row1[id]}>{$row1[title]}</option>";[/code]Might I suggest you name your variables better? You'll thank yourself when you come back to the code a few months from now. Quote Link to comment Share on other sites More sharing options...
marcus Posted December 6, 2006 Author Share Posted December 6, 2006 What is that going to do? It works fine until you get to the point where you see the actual comments and can see all the submit buttons saying delete. Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted December 6, 2006 Share Posted December 6, 2006 if you embed an array into a string like that, you have to put {} around it, or PHP will read up to the point it sees the [ character and then stop, and try to display the "$row1" (which will be an array, so it wont display correctly) you have to tell it to keep looking... egif you do$array['index']php sees$arrayso you gotta do {$array['index']}can be seen in the echo example here: http://www.php.net/manual/en/function.echo.php Quote Link to comment Share on other sites More sharing options...
marcus Posted December 6, 2006 Author Share Posted December 6, 2006 Personally, you're not helping. The problem is the comments will not delete when submitted upon. Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted December 6, 2006 Share Posted December 6, 2006 oh well, I'll leave it here (it's a bit hard to read your code) with a suggestion. if($_COOKIE[admin]){ you should probably check that better, a person could just create a cookie named admin and set it to true. Sorry I couldn't help more then. Quote Link to comment Share on other sites More sharing options...
marcus Posted December 6, 2006 Author Share Posted December 6, 2006 but they would have to create a cookie under my domain Quote Link to comment 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.