Ell20 Posted October 24, 2007 Author Share Posted October 24, 2007 I was just looking at that, i changed it to: WHERE news_id='$newsid' and now when I do the update it updates the bottom update only even if i edit the top one! Link to comment https://forums.phpfreaks.com/topic/74502-solved-edit-message-in-php/page/2/#findComment-376725 Share on other sites More sharing options...
teng84 Posted October 24, 2007 Share Posted October 24, 2007 <?php if(isset($_GET['news_id'])){ $query = "SELECT * FROM news WHERE club_id = '{$_GET['news_id']}'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $newsid = $row['news_id']; $message = $row['message'];//added by teng ?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <textarea name="my_messages" cols="100" rows="10"><?=$message?></textarea> <input name="m_id" type="hidden" value="$newsid"> <input name="submit" type="submit" /> <?php } if (isset($_POST['submit'])) { $message = $_POST['message']; $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>'; } ?> try i use hidden field Link to comment https://forums.phpfreaks.com/topic/74502-solved-edit-message-in-php/page/2/#findComment-376728 Share on other sites More sharing options...
Ell20 Posted October 24, 2007 Author Share Posted October 24, 2007 Unfortunately it dosent work. When you click submit it dosent even say the changes this time! Grr!! Link to comment https://forums.phpfreaks.com/topic/74502-solved-edit-message-in-php/page/2/#findComment-376732 Share on other sites More sharing options...
Ell20 Posted October 24, 2007 Author Share Posted October 24, 2007 Appreciate any help looking for the error in this code - when I edit a news item and press submit, no matter which news item I edit it saves the changes to the bottom news item <?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'"; $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> <hr> <?php } ?> </td> </tr> </table> <?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'];//added by teng ?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <textarea name="my_messages" cols="100" rows="10"><?=$message?></textarea> <input name="submit3" type="submit" /> <?php } if (isset($_POST['submit3'])) { $message = $_POST['news']; $update = "UPDATE news SET news='{$_POST['my_messages']}' WHERE news_id='$newsid'" or die(mysql_error()); mysql_query($update) or die(mysql_error()); echo '<center><h3>Message Updated!</h3></center>'; } ?> Cheers Link to comment https://forums.phpfreaks.com/topic/74502-solved-edit-message-in-php/page/2/#findComment-376735 Share on other sites More sharing options...
teng84 Posted October 24, 2007 Share Posted October 24, 2007 sorry i forgot to add <? <?php if(isset($_GET['news_id'])){ $query = "SELECT * FROM news WHERE club_id = '{$_GET['news_id']}'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $newsid = $row['news_id']; $message = $row['message'];//added by teng ?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <textarea name="my_messages" cols="100" rows="10"><?=$message?></textarea> <input name="m_id" type="hidden" value="<?=$newsid?>"> <input name="submit" type="submit" /> <?php } if (isset($_POST['submit'])) { $message = $_POST['message']; $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>'; } ?> Link to comment https://forums.phpfreaks.com/topic/74502-solved-edit-message-in-php/page/2/#findComment-376737 Share on other sites More sharing options...
Ell20 Posted October 24, 2007 Author Share Posted October 24, 2007 WOW! Excellent, its working Can you just explain why you added the hidden part and what it does? Cheers Link to comment https://forums.phpfreaks.com/topic/74502-solved-edit-message-in-php/page/2/#findComment-376741 Share on other sites More sharing options...
teng84 Posted October 24, 2007 Share Posted October 24, 2007 just to satify your condition on your update see it LOL NAH it take me lot of post haha any ways cheers Link to comment https://forums.phpfreaks.com/topic/74502-solved-edit-message-in-php/page/2/#findComment-376743 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.