edit own message

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

edit own message

Post 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...
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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.
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

can't get it right....sorry...can u post a sample code?
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

post the code you have so far.
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post 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]
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

any help will greatly be appreciated... :)
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

help, help, help pls...... :oops:
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Please stop repeatedly posting merely to push the post back to the top of the list :roll:
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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?
}
Post Reply