Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 KB | None | 0 0
  1. <html>
  2. <body>
  3.  
  4. <table>
  5. <tr>
  6. <td>
  7. <h2>Rhettbook</h2>
  8.  
  9.  
  10.  
  11. <?PHP
  12. /*here's a challenge for oyu
  13. make it do pages
  14. 10 comments per page
  15. to do that, you'll use LIMIT in your sql query
  16. LIMIT <offset>,<max>
  17. so LIMIT 20,10
  18. at the end of your query
  19. Jeff: would display comments 20-30
  20. you'll need to figure out how to set that on the fly depending on what page your on in the comments
  21. and do paging through $_GET
  22. so ?pg=2
  23. would show comments 10-20*/
  24.  
  25. $server = 'legionlab.com';
  26. $username = 'catz';
  27. $password = '12345';
  28. $database = 'All_Your_Base_Are_Belong_to_ME';
  29. date_default_timezone_set('UTC');
  30.  
  31. $db = mysql_connect($server, $username, $password, true);
  32. if(!$db){
  33. die('The grim reaper is going to come eat you'.mysql_error());
  34. }
  35. mysql_select_db($database);
  36. session_start();
  37. if(isset($_POST['color'])){
  38. $color = strip_tags(mysql_real_escape_string($_POST['color']), '<b><u><i><em>');
  39. $_SESSION['color'] = $color;
  40. echo '<style type="text/css">
  41. body{
  42. background-color:'.$color.';
  43. }
  44. </style>';
  45. }
  46.  
  47.  
  48. if(isset($_POST['sort'])){
  49. if(isset($_POST['order'])){
  50. if($_POST['order'] == 'Date'){
  51. $order = 'id';
  52. $select0 = ' selected="selected"';
  53. }else{
  54. $select0 = '';
  55. }
  56. }
  57. if($_POST['order'] == 'Name'){
  58. $order = 'name';
  59. $select1 = ' selected="selected"';
  60. }else{
  61. $select1 = '';
  62. }
  63. if($_POST['order'] == 'Comment'){
  64. $order = 'comment';
  65. $select2 = ' selected="selected"';
  66. }else{
  67. $select2 = '';
  68. }
  69. if(isset($_POST['updown'])){
  70. if($_POST['updown'] == 'Ascending'){
  71. $updown = 'ASC';
  72. $select3 = ' selected="selected"';
  73. }else{
  74. $select3 = '';
  75. }
  76. if($_POST['updown'] == 'Descending'){
  77. $updown = 'DESC';
  78. $select4 = ' selected="selected"';
  79. }else{
  80. $select4 = '';
  81. }
  82. }else{
  83. $updown = 'DESC';
  84. }
  85. }else{
  86. $order = 'id';
  87. $updown = 'DESC';
  88. $select0 = '';
  89. $select1 = '';
  90. $select2 = '';
  91. $select3 = '';
  92. $select4 = '';
  93. }
  94.  
  95.  
  96.  
  97. if(isset($_POST['submit'])){
  98. $comment = strip_tags(mysql_real_escape_string($_POST['comment']), '<b><u><i><em>');
  99. $name = strip_tags(mysql_real_escape_string($_POST['name']), '<b><u><i><em>');
  100. if($name == ''){
  101. $name = 'Anonymous';
  102. }
  103. if($comment == ''){
  104. echo '<b> Enter a comment and/or your name </b><br />';
  105. }else{
  106. $sqlcomment = "INSERT INTO Guestbook (comment, name) VALUES ('$comment', '$name')";
  107. if(mysql_query($sqlcomment)){
  108. echo '<b> Commented! <br /></b>';
  109. }
  110. }
  111. }
  112.  
  113.  
  114.  
  115. if(!isset($_GET['pg'])){
  116. $page = '0';
  117. }else {
  118. $page = ($_GET['pg'] - 1) * 10;
  119. }
  120.  
  121.  
  122. $sqlComDisp = 'SELECT comment, name, timestamp FROM Guestbook ORDER BY '.$order.' '.$updown.' LIMIT '.$page.', 10';
  123.  
  124. $comQuery = mysql_query($sqlComDisp);
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135. //mysql_fetch_assoc();
  136. //mysql_real_escape_string();
  137.  
  138.  
  139.  
  140. ?>
  141.  
  142.  
  143.  
  144.  
  145. <form method="post" target="_self">
  146. Comment
  147. <br />
  148. <textarea name="comment" rows="5" cols="70"></textarea>
  149. <br />
  150. Name:
  151. <br /><input type="text" maxlength="30" size="30" name="name" />
  152. <br />
  153. <input type="submit" name="submit" value="Comment" />
  154. <br />
  155. </form>
  156. <?
  157. echo '<form method="post" target="_self">
  158. Sort by
  159. <select name="order">
  160. <option',$select0,'>Date</option>
  161. <option',$select1,'>Name</option>
  162. <option',$select2,'>Comment</option>
  163. </select>
  164. <select name="updown">
  165. <option',$select3,'>Ascending</option>
  166. <option',$select4,'>Descending</option>
  167. </select>
  168. <input type="submit" name="sort" value="Sort">
  169. </form>';
  170. while($commentDisp = mysql_fetch_assoc($comQuery)){
  171. echo '"'.$commentDisp['comment'].'"','<br />';
  172. echo '&nbsp&nbsp&nbsp&nbsp&nbsp-', $commentDisp['name'], '<font size="2"> ('.date('F j, Y, g:i a',strtotime($commentDisp['timestamp'])).')</font>';
  173.  
  174. echo '<br /><br />';
  175. }
  176. ?>
  177. </td>
  178. <td align="right" valign="top">
  179. <form method="post" target="_self" align="right">
  180. <br /><br /><br /><br /><br />Choose a background color!:
  181. <br />
  182. <input type="text" maxlength="10" size="10" name="color" />
  183. <br />
  184. <input type="submit" name="colorSubmit" value="Change Color" />
  185.  
  186. </form>
  187. </td>
  188. </tr>
  189. </table>
  190.  
  191. <a href="<? echo $_SERVER['PHP_SELF'].'?pg='.$_GET['pg']-1; ?>">Previous </a>
  192. <a href="<? echo $_SERVER['PHP_SELF'].'?pg='.$_GET['pg']+1; ?>"> Next</a>
  193.  
  194.  
  195.  
  196. </body>
  197. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement