Page 1 of 1

edit own message

Posted: Thu Mar 10, 2005 1:54 am
by pleigh
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...

Posted: Thu Mar 10, 2005 3:33 am
by anjanesh
Use parameters - like this forum - phpBB :
for edit : &mode=edit&post=$_GET['PostNo']
for new post : &mode=newtopic
Make sure you check $_GET['PostNo'] and verify whos editing.

Posted: Thu Mar 10, 2005 3:46 am
by pleigh
can't get it right....sorry...can u post a sample code?

Posted: Thu Mar 10, 2005 3:51 am
by patrikG
post the code you have so far.

Posted: Thu Mar 10, 2005 3:57 am
by pleigh
ok...this is the form that i copied from the make new report/message

Code: Select all

<form action="<? $_SERVER['PHP_SELF']; ?>" method="post">
		  <table width="100%" border="0" cellspacing="0" cellpadding="0">
		  <!--spacer-->
		  <tr>
		  	<td width="20%">&nbsp;</td>
			<td width="1%">&nbsp;</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

and

Code: 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]

Posted: Fri Mar 11, 2005 5:08 am
by pleigh
any help will greatly be appreciated... :)

Posted: Fri Mar 11, 2005 6:58 am
by pleigh
help, help, help pls...... :oops:

Posted: Fri Mar 11, 2005 7:05 am
by Chris Corbyn
Please stop repeatedly posting merely to push the post back to the top of the list :roll:

Posted: Fri Mar 11, 2005 4:17 pm
by shiznatix
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..

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'");
}
thats just a idea to use maybe?
}