goosey Posted July 13, 2007 Share Posted July 13, 2007 Okay this is a little script for my website which allows me to post announcements. The problem is only the delete function works and when i try to edit or post and announcement it comes up with an error. The two scripts i am using are; <?php include("agreement.php"); include("config.php"); if ($agreed && $loggedin && $user['isadmin']) { $del_id = $_GET['delete']; $edit_id = $_GET['edit']; $output_text = ""; if (empty($del_id) && empty($edit_id)) { $output_text = ' <form method="post" action="announcementprocess.php"> <strong>Title:</strong><br /> <input type="text" maxlength="30" name="title" /><br /><br /> <strong>News Category:</strong><br /> <select name="category"> <option value="" />Choose a news category... <option value="general" />General <option value="game_updates" />Game Updates <option value="website" />Website <option value="customer_support" />Customer Support <option value="technical" />Technical <option value="behind_the_scenes" />Behind the Scenes </select><br /><br /> <strong>Message:</strong><br /> <textarea cols="40" rows="4" name="msg" wrap="soft"></textarea><br /><br /> <strong>News Icon:</strong><br /> <input name="icon" type="radio" value="article" checked="checked" /> <img src="images/news/article.gif" /> <input name="icon" type="radio" value="penguin" /> <img src="images/news/penguin.gif" alt="Image" width="50" height="50" /> <input name="icon" type="radio" value="bar" /> <img src="images/news/bars.gif" alt="Image" width="50" height="50" /> <input name="icon" type="radio" value="guide" /> <img src="images/news/guide.gif" alt="Image" width="50" height="50" /> <input name="icon" type="radio" value="postbag" /> <img src="images/news/postbag.gif" alt="Image" width="50" height="50" /> <input name="icon" type="radio" value="chicken" /> <img src="images/news/chicken.gif" alt="Image" width="50" height="50" /> <input name="icon" type="radio" value="squirrel" /> <img src="images/news/squirrel.gif" alt="Image" width="50" height="50" /> <input name="icon" type="radio" value="medium_priority" /> <img src="images/news/medium_priority.gif" alt="Image" width="50" height="50" /> <br /> <input name="icon" type="radio" value="technical_2" /> <img src="images/news/technical_2.gif" alt="Image" width="50" height="50" /> <input name="icon" type="radio" value="white_phat" /> <img src="images/news/whitepartyhatwy6.gif" alt="Image" width="50" height="50" /> <input name="icon" type="radio" value="yellow_phat" /> <img src="images/news/yellowpartyhatfv7.gif" alt="Image" width="50" height="50" /> <input name="icon" type="radio" value="earth" /> <img src="images/news/earth_game_updates.gif" alt="Image" width="50" height="50" /> <input name="icon" type="radio" value="beta" /> <img src="images/news/beta.gif" alt="Image" width="50" height="50" /> <input name="icon" type="radio" value="important_yellow" /> <img src="images/news/important_yellow.png" alt="Image" width="50" height="50" /> <input name="icon" type="radio" value="new_button" /> <img src="images/news/New_Button.png" alt="Image" width="50" height="50" /> <input name="icon" type="radio" value="camera" /> <img src="images/news/camera.gif" alt="Image" width="50" height="50" /> <br /> <br /><br/> <input type="submit" name="ok" value="Post!" onClick="disableButton();" /> </form>'; } else if (!empty($edit_id) && empty($del_id)) { $news_edit_result = mysql_query("SELECT * FROM `site_news` WHERE id = '" . $edit_id ."'"); while ($editrow = mysql_fetch_assoc($news_edit_result)) { $old_title = $editrow['title']; $old_msg = $editrow['message']; } $old_msg = str_replace("<br />", "", $old_msg); $output_text = '<form method="post" action="announcementprocess.php"> <strong>New Title:</strong><br /> <input type="text" maxlength="30" name="new_title" value="' . $old_title . '" /><br /><br /> <strong>Edit reason:</strong><br /> <input type="text" maxlength="30" name="edit_reason" value="..." /><br /><br /> <strong>New News Category:</strong><br /> <select name="new_category"> <option value="" />Choose a new news category... <option value="general" />General <option value="game_updates" />Game Updates <option value="website" />Website <option value="customer_support" />Customer Support <option value="technical" />Technical <option value="behind_the_scenes" />Behind the Scenes </select><br /><br /> <strong>New Message:</strong><br /> <textarea cols="40" rows="4" name="new_msg" wrap="soft">' . $old_msg . '</textarea><br /><br /> <strong>New News Icon:</strong><br /> <input name="new_icon" type="radio" value="article" checked="checked" /> <img src="images/news/article.gif" /> <input name="new_icon" type="radio" value="penguin" /> <img src="images/news/penguin.gif" alt="Image" width="50" height="50" /> <input name="new_icon" type="radio" value="bar" /> <img src="images/news/bars.gif" alt="Image" width="50" height="50" /> <input name="new_icon" type="radio" value="guide" /> <img src="images/news/guide.gif" alt="Image" width="50" height="50" /> <input name="new_icon" type="radio" value="postbag" /> <img src="images/news/postbag.gif" alt="Image" width="50" height="50" /> <input name="new_icon" type="radio" value="chicken" /> <img src="images/news/chicken.gif" alt="Image" width="50" height="50" /> <input name="new_icon" type="radio" value="squirrel" /> <img src="images/news/squirrel.gif" alt="Image" width="50" height="50" /> <input name="new_icon" type="radio" value="medium_priority" /> <img src="images/news/medium_priority.gif" alt="Image" width="50" height="50" /> <br /> <input name="new_icon" type="radio" value="technical_2" /> <img src="images/news/technical_2.gif" alt="Image" width="50" height="50" /> <input name="new_icon" type="radio" value="white_phat" /> <img src="images/news/whitepartyhatwy6.gif" alt="Image" width="50" height="50" /> <input name="new_icon" type="radio" value="yellow_phat" /> <img src="images/news/yellowpartyhatfv7.gif" alt="Image" width="50" height="50" /> <input name="new_icon" type="radio" value="earth" /> <img src="images/news/earth_game_updates.gif" alt="Image" width="50" height="50" /> <input name="new_icon" type="radio" value="beta" /> <img src="images/news/beta.gif" alt="Image" width="50" height="50" /> <input name="new_icon" type="radio" value="important_yellow" /> <img src="images/news/important_yellow.png" alt="Image" width="50" height="50" /> <input name="new_icon" type="radio" value="new_button" /> <img src="images/news/New_Button.png" alt="Image" width="50" height="50" /> <input name="new_icon" type="radio" value="camera" /> <img src="images/news/camera.gif" alt="Image" width="50" height="50" /> <input type="hidden" name="edit_id" value="' . $edit_id . '" /> <br /> <br /><br/> <input type="submit" name="ok_edit" value="Post edited message!" /> </form>'; } else if (!empty($del_id) && empty($edit_id)) { $output_text = ' <form method="post" action="announcementprocess.php"> <strong>Are you sure you want to delete this announcement? (ID: ' . $del_id . ' )</strong> <br /><br /> <input type="hidden" name="del_id" value="' . $del_id . '" /> <input type="submit" name="ok_del" value="Yes, delete it!" /> <input type="submit" name="no_del" value="No!" /> </form> '; } include("header.php"); ?> <style> body { background-image: url(/images/bg/background.jpg); background-repeat: repeat-y; background-position: center top; background-color: #000000; } .body { background-image: /images/help/backdrop_745.gif; background-repeat: repeat-y; background-position: center -25px; padding-left: 20px; padding-right: 20px; padding-top: 5px; padding-bottom: 5px; color: #000000; font-family: Arial, Helvetica, sans-serif; font-size: 13px; } .top { background-image: /images/help/backdrop_745.gif; background-repeat: no-repeat; background-position: center 25px; } .bottom { background-image: /images/help/backdrop_745.gif; background-repeat: no-repeat; background-position: center -155px; } hr { width: 100%; color: #382418; height: 1px; border-width: 0 0 1px 0; border-bottom: 1px solid #382418; margin: 0; padding: 0; } h1 { text-align: center; } </style> <script type="text/javascript"> function disableButton() { frm=document.forms[0] frm.ok.disabled=true; frm.ok.value="Loading..."; } </script> <div class="frame wide_e"> <span style="float:right;"><a class="greenlink" href="logout.php">Logout</a></span> <div>You are logged in as <span style="color:#FFBB22;"> <?php echo $_COOKIE['zg_username']; ?></span></div> </div> <table width="765" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td background="/images/help/backdrop_745.gif" class="top"><img src="/images/help/backdrop_765_top.gif" width="765" height="50" /></td> </tr> <tr> <td background="/images/help/backdrop_745.gif" class="body"><hr /> <b>Location: <a class="brownlink" href="admincentre.php">Admin Centre</a> > <a class="brownlink" href="announcement.php">Announcements</a></b> <hr /> <h2>Announcement Management</h2> <div style="text-align: justify;"> <?php echo $output_text; ?></div> <br /> <br /> </td> </tr> <tr> <td background="/images/help/backdrop_745.gif" class="bottom"><img src="/images/help/backdrop_765_bottom.gif" width="765" height="50" /></td> </tr> </table> <br /> <?php include("footer.php"); } ?> and <?php include("config.php"); if ($loggedin && $user['isadmin']) { if (isset($_POST['ok'])) { $title = $_POST['title']; $msg = $_POST['msg']; $news_icon = $_POST['icon']; $news_category = $_POST['category']; $date = date(j."-".M."-".Y); $msg = str_replace(" ", "<br />", $msg); $news_insert_query = "INSERT INTO `site_news` VALUES('', '" . $title . "', '" . $msg . "', '" . $news_category . "', '" . $date . "', '" . $news_icon . "', '" . $user['username'] . "', '')"; mysql_query($news_insert_query); echo '<meta http-equiv="refresh" content="0;url=redirect.php?to=index.php" />'; } else if (isset($_POST['ok_del']) || isset($_POST['no_del'])) { if (isset($_POST['ok_del'])) { mysql_query("DELETE FROM `site_news` WHERE `id` = '" . $_POST['del_id'] . "'"); echo '<meta http-equiv="refresh" content="0;url=redirect.php?to=index.php" />'; } else if(isset($_POST['no_del'])) { echo '<meta http-equiv="refresh" content="0;url=index.php" />'; } } else if (isset($_POST['ok_edit'])) { $new_title = $_POST['new_title']; $new_msg = $_POST['new_msg']; $new_news_icon = $_POST['new_icon']; $new_news_category = $_POST['new_category']; $edit_reason = $_POST['edit_reason']; $new_msg = str_replace(" ", "<br />", $new_msg); $news_update_query = "UPDATE `site_news` SET `title` = '" . $new_title . "', `message` = '" . $new_msg . "', `category` = '" . $new_news_category . "', `icon` = '" . $new_news_icon . "', `edited` = '<i>Edited on " . $date . " by '" . $user['username'] . ". Reason: " . $edit_reason . "</i>' WHERE `id` = '" . $_POST['edit_id'] . "'"; mysql_query($news_update_query); echo '<meta http-equiv="refresh" content="0;url=redirect.php?to=index.php" />'; } else { echo 'Error'; } } else { echo '<meta http-equiv="refresh" content="0;url=index.php" />'; } ?> I desperately need help with this because i need this done for tommorrow. If anyone can help thanks so much! The error i am experiencing is coming from else { echo 'Error'; at the end of the script i know that but i can't figure out what the problem is. Sorry if this is in the wrong section. Thanks so much.... goosey Quote Link to comment https://forums.phpfreaks.com/topic/59778-solved-serious-head-ache/ Share on other sites More sharing options...
MadTechie Posted July 13, 2007 Share Posted July 13, 2007 what does this return echo "loggedin="; //<--Added var_dump($loggedin); //<--Added echo "isadmins="; //<--Added var_dump($user['isadmin']); //<--Added echo "POST=";//<--Added print_r($_POST);//<--Added if ($loggedin && $user['isadmin']) { EDIT: oops also add POST Quote Link to comment https://forums.phpfreaks.com/topic/59778-solved-serious-head-ache/#findComment-297176 Share on other sites More sharing options...
goosey Posted July 13, 2007 Author Share Posted July 13, 2007 loggedin=bool(true) isadmins=bool(true) Quote Link to comment https://forums.phpfreaks.com/topic/59778-solved-serious-head-ache/#findComment-297180 Share on other sites More sharing options...
infid3l Posted July 13, 2007 Share Posted July 13, 2007 true and true Can you do: print_r($_POST); at the top of the second script please? (Post the result) Quote Link to comment https://forums.phpfreaks.com/topic/59778-solved-serious-head-ache/#findComment-297183 Share on other sites More sharing options...
goosey Posted July 13, 2007 Author Share Posted July 13, 2007 Array ( ) Quote Link to comment https://forums.phpfreaks.com/topic/59778-solved-serious-head-ache/#findComment-297185 Share on other sites More sharing options...
infid3l Posted July 13, 2007 Share Posted July 13, 2007 Array ( ) Yep, that's your problem. You're not getting any POST data! Check your HTML. Quote Link to comment https://forums.phpfreaks.com/topic/59778-solved-serious-head-ache/#findComment-297186 Share on other sites More sharing options...
MadTechie Posted July 13, 2007 Share Posted July 13, 2007 is the 2nd script called announcementprocess.php? Quote Link to comment https://forums.phpfreaks.com/topic/59778-solved-serious-head-ache/#findComment-297187 Share on other sites More sharing options...
goosey Posted July 13, 2007 Author Share Posted July 13, 2007 Oh, sorry. I did a small error, i put it in the first script :$ Array ( [title] => test [category] => website [msg] => test [icon] => article ) Error ^ is the actual result and yes 2nd script is announcement proccess Quote Link to comment https://forums.phpfreaks.com/topic/59778-solved-serious-head-ache/#findComment-297188 Share on other sites More sharing options...
infid3l Posted July 13, 2007 Share Posted July 13, 2007 Oh, sorry. I did a small error, i put it in the first script :$ Array ( [title] => test [category] => website [msg] => test [icon] => article ) Error ^ is the actual result and yes 2nd script is announcement proccess Paste the result you get from clicking all the different submit buttons. The error is in your HTML. Quote Link to comment https://forums.phpfreaks.com/topic/59778-solved-serious-head-ache/#findComment-297190 Share on other sites More sharing options...
MadTechie Posted July 13, 2007 Share Posted July 13, 2007 try if (empty($del_id) && empty($edit_id)) { $output_text = ' <form method="post" action="announcementprocess.php"> <input name="ok" type="hidden" value="test" /> <strong>Title:</strong><br /> note the line <input name="ok" type="hidden" value="test" /> Quote Link to comment https://forums.phpfreaks.com/topic/59778-solved-serious-head-ache/#findComment-297192 Share on other sites More sharing options...
goosey Posted July 13, 2007 Author Share Posted July 13, 2007 Wow, it worked! Finally! i've been trying for hours! Thank you guys very very much for taking the time to try and help me Quote Link to comment https://forums.phpfreaks.com/topic/59778-solved-serious-head-ache/#findComment-297195 Share on other sites More sharing options...
MadTechie Posted July 13, 2007 Share Posted July 13, 2007 Welcome, can you please click solved also the "reason" it wasn't working was becuase the line <input type="submit" name="ok" value="Post!" onClick="disableButton();" /> basically it wasn't posting the OK so i added a hidden one Quote Link to comment https://forums.phpfreaks.com/topic/59778-solved-serious-head-ache/#findComment-297197 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.