Advertisement
Guest User

Untitled

a guest
Aug 14th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1.  
  2. <html>
  3. <body>
  4.  
  5. <table>
  6. <tr>
  7. <td>
  8. <h2>Rhettbook</h2>
  9.  
  10.  
  11.  
  12. <?PHP
  13. /*here's a challenge for oyu
  14. make it do pages
  15. 10 comments per page
  16. to do that, you'll use LIMIT in your sql query
  17. LIMIT <offset>,<max>
  18. so LIMIT 20,10
  19. at the end of your query
  20. Jeff: would display comments 20-30
  21. you'll need to figure out how to set that on the fly depending on what page your on in the comments
  22. and do paging through $_GET
  23. so ?pg=2
  24. would show comments 10-20*/
  25.  
  26. $server = '72.14.188.135';
  27. $username = 'catz';
  28. $password = '12345';
  29. $database = 'All_Your_Base_Are_Belong_to_ME';
  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. $sqlComDisp = 'SELECT comment, name, timestamp FROM Guestbook ORDER BY '.$order.' '.$updown;
  115.  
  116. $comQuery = mysql_query($sqlComDisp);
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127. //mysql_fetch_assoc();
  128. //mysql_real_escape_string();
  129.  
  130.  
  131.  
  132. ?>
  133.  
  134. <form method="post" target="_self">
  135. Comment
  136. <br />
  137. <textarea name="comment" rows="5" cols="70"></textarea>
  138. <br />
  139. Name:
  140. <br /><input type="text" maxlength="30" size="30" name="name" />
  141. <br />
  142. <input type="submit" name="submit" value="Comment" />
  143. <br />
  144. </form>
  145. <?
  146. echo '<form method="post" target="_self">
  147. Sort by
  148. <select name="order">
  149. <option',$select0,'>Date</option>
  150. <option',$select1,'>Name</option>
  151. <option',$select2,'>Comment</option>
  152. </select>
  153. <select name="updown">
  154. <option',$select3,'>Ascending</option>
  155. <option',$select4,'>Descending</option>
  156. </select>
  157. <input type="submit" name="sort" value="Sort">
  158. </form>';
  159. while($commentDisp = mysql_fetch_assoc($comQuery)){
  160. echo '"'.$commentDisp['comment'].'"','<br />';
  161. echo '&nbsp&nbsp&nbsp&nbsp&nbsp-', $commentDisp['name'], '<font size="2"> ('.date('F j, Y, g:i a',strtotime($commentDisp['timestamp'])).')</font>';
  162.  
  163. echo '<br /><br />';
  164. }
  165. ?>
  166. </td>
  167. <td align="right" valign="top">
  168. <form method="post" target="_self" align="right">
  169. <br /><br /><br /><br /><br />Choose a background color!:
  170. <br />
  171. <input type="text" maxlength="10" size="10" name="color" />
  172. <br />
  173. <input type="submit" name="colorSubmit" value="Change Color" />
  174.  
  175. </form>
  176. </td>
  177. </tr>
  178. </table>
  179.  
  180. </body>
  181. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement