EDIT2! It shows: Thank you post edited, while the post is as it was. Also, I'll update the code
Hello!
I found a forum tutorial a while ago, and it worked. Now, I thought of adding EDIT DELETE LOCK etc. stuff to it. So I don't have to go to PHPMYADMIN and so that members also can edit their posts.
I've gotten to the part where you get a text area where is your original post (with all the tags), and two buttons (Save and cancel). Also, in the left table there is info on the author. What doesn't work - editing.
I somehow never have done editing of anything in a form correctly, if you know what I mean...
Anyways, here's the source:
<?php session_start(); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" > <title>Techgeeks.oo.lv - from websites to graphics, to music</title> <link href="style.css" rel="stylesheet" type="text/css"> <style type="text/css"> a:hover { background-color: #666; } a { text-decoration:none } </style> <style type="text/css"> :link { color: #000 } :visited { color: #000 } :active { color: #000 } </style> </head> <body> <?php include('header.php'); include('connect.php'); ?> <div id=wrapper> <div id=main> <?php //PROCESS FORM if(isset($_POST['editpost'])) { $id = $_POST['id']; $id2 = $_POST['postid']; $getpost = "SELECT a.*, b.Username, b.Status, b.id FROM forum a, users b WHERE postid = '$id2' AND a.Author = b.Username"; $getpost2 = mysql_query($getpost) or die(mysql_error()); $getpost3 = mysql_fetch_array($getpost2); //ERROR CHECK //Length check if(!strlen($_POST['doedit']) > 0) { die("<font color='red'><b>Error!</b> You must have a post (i.e. you need a post longer than 1 letter)!</font>"); } //END OF ERROR CHECK $newpost = $_POST['posttoedit']; $updatepost = "UPDATE Forum SET post = $newpost WHERE post = '$id'"; $updatepost2 = mysql_query($updatepost) or die(mysql_error()); if($updatepost2) { echo "Thank you, post edited! <a onClick='history.back(2)'>Click here</a> to go back."; } else { echo "<font color='red'><b>Error!</b> There was an error while editing your post. Please go back and try again.</font>"; } } //END OF FORM PROCESS $username = $_SESSION['s_username']; $perm="SELECT forumEDIT, forumDEL, forumLOCK, forumUNLOCK FROM Users WHERE Username = '$username'"; $perm2=mysql_query($perm) or die(mysql_error()); $perm3=mysql_fetch_array($perm2); //ERROR CHECK //Log in check if(!isset($_SESSION['s_username'])) { die("<font color='red'><b>Error!</b> You must <a href='../login.php'>log in</a> to edit a post!</font>"); //If not logged in, stop } //Permission check if($perm3['forumĖDIT'] == n) { die("<font color='red'><b>Error!</b> You don't have permissions to edit a post!</font>"); //If the user doesn't have the permissions, stop } //Post check /*if(!isset($_GET['id'])) { die("<font color='red'><b>Error!</b> You haven't selected a post to edit!</font>"); //If no post selected, stop }*/ //END OF ERROR CHECK $id = $_GET['id']; $getpost = "SELECT a.*, b.Username, b.Status, b.id FROM forum a, users b WHERE postid = '$id' AND a.Author = b.Username"; $getpost2 = mysql_query($getpost) or die(mysql_error()); $getpost3 = mysql_fetch_array($getpost2); ?> <table class='maintable'> <tr class='headline'><td width=20%>Author</td><td width=80%>Post</td></tr> <tr class="mainrow"><td valign="top"> <?php echo "<a href='../profiles.php?id=".$getpost3['id']."'>".$getpost3['Username']."</a><br>Status: ".$getpost3['Status'].""; ?> </td><td><form name="editpost" action="?id=<?php echo $id; ?>" method="post"><?php print"<input type=\"button\" onClick=\"document.editpost.posttoedit.value+=''\" value=\"Bold\" name=\"bold\" title=\"Add Bold\" ><input type=\"button\" onClick=\"document.post.yourpost.value+=''\" value=\"Italic\" name=\"Italic\" title=\"Add Italic\" ><input type=\"button\" onClick=\"document.post.yourpost.value+=''\" value=\"Underline\" name=\"underline\" title=\"Add Underline\" ><input type=\"button\" onClick=\"document.post.yourpost.value+=''\" value=\"Strikethrough\" name=\"strikethrough\" title=\"Add Strikethrough\" ><input type=\"button\" onClick=\"document.post.yourpost.value+=''\" value=\"Image\" name=\"image\" title=\"Add an Image\" ><input type=\"button\" onClick=\"document.post.yourpost.value+='code/code'\" value=\"Code\" name=\"code\" title=\"Add a Code\" ><input type=\"button\" onClick=\"document.post.yourpost.value+='[url="http://www.domain.com"]Link name here[/url]'\" value=\"Link\" name=\"link\" title=\"Add a Link\" ><br>"; ?> <textarea cols="50" rows="10" name="posttoedit"><?php echo $getpost3['post']; ?></textarea><br> <input type="submit" name="doedit" value="Edit!"><input type="button" onClick="history.back(1)" value="Cancel edit!"><input type="hidden" value="<?php echo $id; ?>" name="postid"></form></td></tr> </table> </div> </div> </body> </html>
What is the problem?
Edited by Edmachine, 02 October 2007 - 08:20 AM.