Guest User

Untitled

a guest
Apr 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(-1); mysqli_report(MYSQLI_REPORT_ALL & ~MYSQLI_REPORT_INDEX);
  3.  
  4. include 'header.php';
  5. include 'dbconnect.php';
  6.  
  7. //GATHER MY POST THAT MATCHES THE POST THE USER CLICKS TO EDIT AND DISPLAY TO THEM!
  8. $sql = "SELECT forumpost_ID, forumpost_Text
  9. FROM hw7_forumpost
  10. WHERE forumpost_ID =" . mysqli_real_escape_string($connectDB, $_GET['eid']);
  11.  
  12. $result = mysqli_query($connectDB,$sql);
  13.  
  14. if(!$result){ echo 'Something went wrong, please try again later.'; }
  15.  
  16. else{
  17. while($row = mysqli_fetch_array($result)){
  18. echo'<form action="" method="post">';
  19. echo'<div>';
  20. echo'<textarea name="contents" rows="15" cols="50">'.$row[1].'</textarea>';
  21. echo'</div><div>';
  22. echo'<input type="submit" value="Add Post">';
  23. echo'</div>';
  24. }echo '</form>';
  25. }
  26.  
  27. if(isset($_POST['contents'])){
  28. $contents = trim($_POST['contents']);
  29. editpost($_GET['eid'], $contents);
  30. echo ('Your post has been updated!');
  31. header('index.php');
  32. die();
  33. }
  34.  
  35. include 'footer.php';
  36.  
  37. /********************************************
  38. edit function
  39. **********************************************/
  40. function editpost($id, $contents){
  41. global $connectDB;
  42. $id = (int)$id;
  43. $contents = mysqli_real_escape_string($connectDB, $contents);
  44. $sql = "UPDATE hw7_forumpost SET forumpost_Text=".$contents." WHERE forumpost_ID= ".$id;
  45. $result = mysqli_query($connectDB, $sql);
  46. }
  47. ?>
Add Comment
Please, Sign In to add comment