Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. news.php
  2. <html>
  3. <h1>News</h1>
  4. <hr>
  5. <?php
  6.  
  7. // connect
  8. mysql_connect("localhost","root","") or die(mysql_error());
  9. mysql_select_db("newssystem") or die(mysql_error());
  10.  
  11. //query the db
  12. $getnews = mysql_query("SELECT * FROM news") or die(mysql_query());
  13.  
  14. while ($row = mysql_fetch_assoc($getnews))
  15. {
  16.  
  17. // get data
  18. $id = $row['id'];
  19. $title = $row['title'];
  20. $body = $row['body'];
  21. $date = $row['date'];
  22.  
  23. echo "
  24. <b>$title<b> posted on <i>$date</i><br>
  25. ";
  26.  
  27. echo nl2br($body);
  28.  
  29. echo "<hr>
  30. ";
  31. }
  32. ?>
  33. <hr>
  34. </html>
  35.  
  36.  
  37. post.php
  38.  
  39. <html>
  40. <h1>Post news</h1>
  41. <hr>
  42. <?php
  43. if ($_POST['post'])
  44. {
  45.  
  46. //get data
  47. $title = $_POST['title'];
  48. $body = $_POST['body'];
  49. // check for existance
  50. if ($title&&$body)
  51. {
  52. // connect
  53. mysql_connect("localhost","root","") or die(mysql_error());
  54. mysql_select_db("newssystem") or die(mysql_error());
  55.  
  56. $date = date("Y-m-d");
  57. //insert data
  58. $insert = mysql_query("INSERT INTO news VALUES('','$title','$body','$date')") or die(mysql_error());
  59. die("The news has been posted.");
  60. }
  61. else
  62. echo "Please fill out title and body.";
  63. }
  64. ?>
  65. <form action='post.php' method='POST'>
  66. Title:<br>
  67. <input type='text' name='title'><p>
  68.  
  69. Body:<br>
  70. <textarea rows='6' cols='35' name='body'></textarea><p>
  71.  
  72. <input type='submit' name='post' value='Post News'>
  73. <hr
  74. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement