Jump to content

[SOLVED] Edit Message In PHP


Ell20

Recommended Posts

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.