Ell20 Posted October 24, 2007 Share Posted October 24, 2007 Hey, ive been working on this code for a while now. Im sure I had it working earlier to prefection but now its not working as its should but I cant work out what I have changed to stop it working. The idea of the code is that when the edit button is pressed the message from which the edit button was pressed appears in the textarea, then once the Edit News button is pressed the changes are saved. There is also a delete button which can be used to delete a news message from the page. At the moment when I pressed the Edit button its putting the news into the textarea but at the same time it runs the Delete code and deletes the news with the message "News Message Deleted". Appreciate any help on working out where I am going wrong. Cheers <?php require_once ('includes/errors.inc'); $page_title = 'News'; include_once ('includes/header.html'); require_once ('../mysql_connect.php'); include_once ('includes/functions.php'); $id = $_SESSION['club_id']; $clubinfo=getClubInfo($id, '*'); ?> <br /> <br /> <html> <body> <table width="60%" align="center" border="0" cellpadding="0" cellspacing="0" class="game"> <tr> <th><?=$clubinfo['clubn']?> News</th> </tr> <tr> <td> <?php $club_id = mysql_query("SELECT club_id FROM users WHERE user_id = '{$_SESSION['user_id']}'") OR DIE(mysql_error()); $row = mysql_fetch_assoc($club_id); $club_id = $row['club_id']; $clubname = mysql_query("SELECT clubn FROM club WHERE club_id = '$club_id'") OR DIE(mysql_error()); $row = mysql_fetch_assoc($clubname); $clubname = $row['clubn']; $message = mysql_query("SELECT * FROM news WHERE club_id = '$club_id'") OR DIE(mysql_error()); $row = mysql_fetch_assoc($message); $news = $row['news']; $query = "SELECT * FROM news WHERE club_id = '$club_id' ORDER BY 'news_id' DESC"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $newsid = $row['news_id']; echo "<b>Title: </b>" ; echo $row['title']; echo "<br>"; echo $row['news']; echo "<br>"; ?> <a href='<?=$_SERVER['PHP_SELF']."?news_id=$newsid";?>&mode=edit'>Edit News</a> | <a href='<?=$_SERVER['PHP_SELF']."?news_id=$newsid";?>&mode=delete'>Delete News</a> <hr> <?php } ?> </td> </tr> </table> <?php if (isset($_SESSION['user_id'])){ $sql = "SELECT member_type FROM users WHERE user_id = '{$_SESSION['user_id']}' LIMIT 1"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); if ($row['member_type'] == "Admin") { $query = mysql_query("SELECT news FROM news WHERE club_id='$club_id'") or die(mysql_error()); $row = mysql_fetch_assoc($query) or die(mysql_error()); $message = $row['news']; ?> <br> <br> <table border="1" align="center" cellspacing="0" border="0" class="game"> <th colspan="6"> Tags: </th> <tr> <td> Bold Text: <b>Text Here</b> </td> <td> Italic Text: <i>Text Here</i> </td> <td> Center Text: <center>Text Here</center> </td> </tr> <tr> <td> New Paragraph: <p> </td> <td> Insert Image: <img src="Link"/> </td> <td> Text Colour: <font color=colour>Text Here</font> </td> </tr> </table> <br> <?php if (isset($_POST['submit2'])) { require_once ('../mysql_connect.php'); $title = escape_data($_POST['title']); $news = escape_data($_POST['news']); $query = "INSERT INTO news (club_id, news, title) VALUES ('$id', '$news', '$title')"; $result = @mysql_query ($query); if ($result) { echo '<h3>New News Message Created!</h3>'; } } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table width="36%" border="0" align="center" cellspacing="0" border="0" class="game"> <tr> <th> Create New News: </th> </tr> <tr> <td> Title: <input type="text" name="title" size="60" maxlength="80" value="<?php if (isset($_POST['title'])) echo $_POST['title']; ?>" /> </td> </tr> <tr> <td>News: <input type="text" name="news" size="60" maxlength="1000" value="<?php if (isset($_POST['news'])) echo $_POST['news']; ?>" /> </td> </tr> <tr> <td align="center"> <?php echo "<input name=\"submit2\" value=\"Create News\" type=\"submit\" />"; ?> </td> </tr> </table> <?php echo "</form>"; ?> <br> <?php if(isset($_GET['news_id'])){ $query = "SELECT * FROM news WHERE news_id = '{$_GET['news_id']}'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $newsid = $row['news_id']; $message = $row['news']; $title = $row['title']; if ($_GET['news_id']){ mysql_query("DELETE FROM news WHERE news_id='$newsid'") or die(mysql_error()); echo '<center><h3>Message Deleted!</h3></center>'; } ?> <table width="36%" border="0" align="center" cellspacing="0" border="0" class="game"> <tr> <th> Editing Post: <?=$title?> </th> </tr> <tr> <td> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <textarea name="my_messages" cols="91" rows="10"><?=$message?></textarea> <input name="m_id" type="hidden" value="<?=$newsid?>"> </td> </tr> <tr> <td align="center"> <input name="submit3" value="Edit News" type="submit" /> </td> </tr> </form> </table> <?php } if (isset($_POST['submit3'])) { $message = $_POST['news']; $update = "UPDATE news SET news='{$_POST['my_messages']}' where news_id='{$_POST['m_id']}'" or die(mysql_error()); mysql_query($update) or die(mysql_error()); echo '<center><h3>Message Updated!</h3></center>'; }}}}} ?> </body> </html> <?php include_once ('includes/footer.html'); ?> 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.