twsowerby Posted December 7, 2007 Share Posted December 7, 2007 Hi, Trying to create a script for editing posts in a forum via a form. I'm a little new to php and would appreciate some help with it as I can't seem to get it to work. At the moment when i submit the form it doesnt return an error, it just doesnt do anything to the original post. Here is what I have so far: <?php // File: edit.php // define('IN_FORUM', true); include_once "sqlconnect.php"; include_once "includes/functions.php"; include "includes/header.php"; echo "<link rel='stylesheet' href='style.css' type='text/css'>"; echo "<table class='maintables'>"; echo "<tr class='headline'><td>Reply</td></tr>"; echo "<tr class='maintables'><td>"; if(isset($_POST['submit'])) { $name=$_POST['name']; $yourpost=$_POST['yourpost']; $title=$_POST['title']; $id=$_POST['postid']; if(strlen($title)<1) { echo "You did not type in a name."; //no name entered } else if(strlen($yourpost)<1) { echo "You did not type in a post."; //no post entered } else { $thedate=date("U"); //get unix timestamp $displaytime=date("F j, Y, g:i a"); //we now strip HTML injections $subject=strip_tags($subject); $title=strip_tags($title); $yourpost=strip_tags($yourpost); $updatepost="Update forum_posts set title='$title', post='$yourpost', showtime='$displaytime', lastrepliedto='$thedate' where postid='$id'"; mysql_query($updatepost) or die("Could not update post"); echo "Message edited, go back to <A href='message.php?id=$id'>Message</a>."; } } else { $id=$_GET['postid'];echo "<form action='edit.php' method='post'>"; echo "Title:<br>"; echo "<input type='text' name='title' size='20'><br>"; echo "Your message:<br>"; echo "<textarea name='yourpost' rows='5' cols='40'></textarea><br>"; echo "<input type='submit' name='submit' value='submit'></form>"; } echo "</td></tr></table>"; include "includes/footer.php"; ?> Thanks! Tom Link to comment https://forums.phpfreaks.com/topic/80665-editing-posts-in-a-forum/ Share on other sites More sharing options...
JacobYaYa Posted December 7, 2007 Share Posted December 7, 2007 I hope that is not how you code with the whole white space frenzy. If you look at your update form down the bottom it looks as though you are assigning $_GET['postid'] to id but not doing anything with it. Chuck $id into a hidden input on that form and this should be sweet. echo '<input type="hidden" name="postid" value="'.$_GET['postid'].'" />'; Is what you need to put in the form in case your unsure. Link to comment https://forums.phpfreaks.com/topic/80665-editing-posts-in-a-forum/#findComment-409215 Share on other sites More sharing options...
twsowerby Posted December 7, 2007 Author Share Posted December 7, 2007 Thanks, I'll have a go with that. White space frenzy? lol im pretty new to php, did I overlook a coding best practice? Tom Link to comment https://forums.phpfreaks.com/topic/80665-editing-posts-in-a-forum/#findComment-409220 Share on other sites More sharing options...
Yesideez Posted December 7, 2007 Share Posted December 7, 2007 I hope that is not how you code with the whole white space frenzy. There's no right and wrong way to use PHP as such but there are methods to help make things easy to read. Indenting like the OP has used is great when using loops and if statements. Sometimes I add blank lines between code depending on what the function is and how often I'll be maintaining/editing it. twsowerby, instead of having the entire file as PHP code you can use IF statements like this: <?php if ($_POST['submit']) { $name=$_POST['name']; $yourpost=$_POST['yourpost']; } else { ?> <form action="" method="post"> Name <input type="text" name="name" value="<?=$name?>" /><br /> Post <textarea name="yourpost" cols="60" rows="10"><?=nl2br($yourpost)?></textarea> <?php } ?> Just an example piece of code Link to comment https://forums.phpfreaks.com/topic/80665-editing-posts-in-a-forum/#findComment-409222 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.