Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(-1); mysqli_report(MYSQLI_REPORT_ALL & ~MYSQLI_REPORT_INDEX);
- include 'header.php';
- include 'dbconnect.php';
- //GATHER MY POST THAT MATCHES THE POST THE USER CLICKS TO EDIT AND DISPLAY TO THEM!
- $sql = "SELECT forumpost_ID, forumpost_Text
- FROM hw7_forumpost
- WHERE forumpost_ID =" . mysqli_real_escape_string($connectDB, $_GET['eid']);
- $result = mysqli_query($connectDB,$sql);
- if(!$result){ echo 'Something went wrong, please try again later.'; }
- else{
- while($row = mysqli_fetch_array($result)){
- echo'<form action="" method="post">';
- echo'<div>';
- echo'<textarea name="contents" rows="15" cols="50">'.$row[1].'</textarea>';
- echo'</div><div>';
- echo'<input type="submit" value="Add Post">';
- echo'</div>';
- }echo '</form>';
- }
- if(isset($_POST['contents'])){
- $contents = trim($_POST['contents']);
- editpost($_GET['eid'], $contents);
- echo ('Your post has been updated!');
- header('index.php');
- die();
- }
- include 'footer.php';
- /********************************************
- edit function
- **********************************************/
- function editpost($id, $contents){
- global $connectDB;
- $id = (int)$id;
- $contents = mysqli_real_escape_string($connectDB, $contents);
- $sql = "UPDATE hw7_forumpost SET forumpost_Text=".$contents." WHERE forumpost_ID= ".$id;
- $result = mysqli_query($connectDB, $sql);
- }
- ?>
Add Comment
Please, Sign In to add comment