edit own message
Moderator: General Moderators
edit own message
ok i have a question here....what logic should i make if for example, i have a make new message form that is able to post a new message....i want to make an edit form so user can edit that message he made....i want to use the same form i used in my make new message form....but i also want the current message to appear, get the data from the database so it will appear in my edit form....i already copied the make new message but i'm stuck from here, don't know what i should code to perform my idea....
thanks...
thanks...
ok...this is the form that i copied from the make new report/message
feyd | Please use
Code: Select all
<form action="<? $_SERVER['PHP_SELF']; ?>" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<!--spacer-->
<tr>
<td width="20%"> </td>
<td width="1%"> </td>
<td width="79%">
<?
$id = $_SESSION['userID'];
//submit conditionals
if (isset($_POST['submit']))
{
$message = NULL;
//verify title
if (empty($_POST['topic']))
{
$t = FALSE;
$message .= 'Enter the topic of your report!<br>';
}
else
{
$t = addslashes($_POST['topic']);
}
//verify accomplishment
if (empty($_POST['accomplishment']))
{
$a = FALSE;
$message .= 'Enter your accomplishment report!<br>';
}
else
{
$a = addslashes($_POST['accomplishment']);
}
//verify issue
if (empty($_POST['issue']))
{
$i = FALSE;
$message .= 'Enter your issue report!<br>';
}
else
{
$i = addslashes($_POST['issue']);
}
//verify recommendation
if (empty($_POST['recommendation']))
{
$r = FALSE;
$message .= 'Enter your recommendation report!<br>';
}
else
{
$r = addslashes($_POST['recommendation']);
}
if ($t && $a && $i && $r)
{
$query = "INSERT INTO posts(userID, topic, accomplishment, issue, recommendation, postdate, postupdate)
VALUES('$id','$t','$a','$i','$r', NOW(), NOW())";
$result = @mysql_query($query) or die(mysql_error());
if ($result)
{
echo '<b>Your report has been recorded</b>';
echo '<meta http-equiv="refresh" content="3;url=http://localhost/mysample/report.php">';
exit();
}
else
{
$message .= 'Your report cannot be recorded due to system error<br>'.mysql_error();
}
mysql_close();
}
else
{
$message .= 'Please try again<br>';
}
}
if (isset($message))
{
echo '<font color="red">', $message, '</font>';
}
?>
</td>
</tr>
<!--title-->
<tr>
<td width="20%" align="right"><b>TOPIC</b></td>
<td width="1%"><b>:</b></td>
<td width="79%"><input name="topic" style="width:350px" type="text" value="<? if (isset($_POST['topic'])) echo $_POST['topic']; ?>" size="40" maxlength="40"></td>
</tr><br>
<!--accomplishments-->
<tr valign="top">
<td width="20%" align="right"><b>ACCOMPLISHMENT</b></td>
<td width="1%"><b>:</b></td>
<td width="79%"><textarea name="accomplishment" style="width:350px" cols="40" rows="6"></textarea></td>
</tr>
<!--issues-->
<tr valign="top">
<td width="20%" align="right"><b>ISSUES</b></td>
<td width="1%"><b>:</b></td>
<td width="79%"><textarea name="issue" style="width:350px" cols="40" rows="6"></textarea></td>
</tr>
<!--recommendations-->
<tr valign="top">
<td width="20%" align="right"><b>RECOMMENDATION</b></td>
<td width="1%"><b>:</b></td>
<td width="79%"><textarea name="recommendation" style="width:350px" cols="40" rows="6"></textarea></td>
</tr>
<tr valign="top">
<td width="20%"></td>
<td width="1%"></td>
<td width="79%"><input type="submit" name="submit" value="submit report" class="buttonformat"></td>
</tr>
</table>
</form>feyd | Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
i dont understand what you want? you want to be able to update information that was previously put into a db? why not do somtin like..
thats just a idea to use maybe?
}
Code: Select all
$qry = mysql_query("SELECT * FROM table WHERE userID='$id' AND msgID='$msgID'");
echo '<form action='234234.php' method='post'>';
while ($info = mysql_fetch_assoc($qry)){
echo "
<textarea name='amazing'>".$info['field_that_you_want_to_edit']."</textarea>
<input type='submit' name='submit' value='submit'>
";
}
echo '</form>';
if (isset($submit)){
$qry = mysql_query("UPDATE table SET message='$amazing' WHERE userID='$id' AND msgID='$msgID'");
}}