Advertisement
Guest User

Untitled

a guest
Aug 14th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.96 KB | None | 0 0
  1. <?php
  2. //Please set the following variables for your MySQL database:
  3. //Please set the following variables for your MySQL database:
  4. //it is highly recommended that you restrict access for the user for security reasons
  5. //it only needs "INSERT" privileges
  6.  
  7. $db_hostname = "mysql5.000webhost.com"; //usually "localhost be default"
  8. $db_username = "a1636860_root"; //your user name
  9. $db_pass = "dock54"; //the password for your user
  10. $db_name = "a1636860_wwa"; //the name of the database
  11.  
  12.  
  13. /*MYSQL DATABASE CONNECTION/ TRACKING FUNCTIONS
  14. --------------------------------------*/
  15. // connect to database
  16. $dbh = mysql_connect ($db_hostname, $db_username, $db_pass) or die ('I cannot connect to the database because: ' . mysql_error());
  17. mysql_select_db ($db_name);
  18.  
  19.  
  20. ?>
  21. <style type="text/css">
  22. body {
  23. font-family: Helvetica, sans-serif;
  24. font-size: 12px;
  25. }
  26. </style>
  27.  
  28.  
  29. //quick script to make the data look nice
  30. function formatDate($val)
  31. {
  32. list($date, $time) = explode(" ", $val);
  33. list($year, $month, $day) = explode("-", $date);
  34. list($hour, $minute, $second) = explode (":", $time);
  35. return date("l, m.j.y @ H:ia", mktime($hour, $minute, $second, $month, $day, $year));
  36. }
  37.  
  38.  
  39.  
  40. function getComments($tutid){
  41. //creates a function that can easily be called from any page
  42.  
  43. //create the css code to make the form look good. You can edit this to change colors, etc:
  44. echo "
  45. <style>
  46. /*COMMENTS
  47. *------------------------------------*/
  48.  
  49. .postedby {
  50. padding: 0 0 0 18px;
  51. background: url(images/abullet.gif) no-repeat 0 4px;
  52. }
  53.  
  54. h3.formtitle {
  55. margin : 0px 0px 0px 0px;
  56. border-bottom: 1px dotted #ccc;
  57. padding-bottom: 8px;
  58. }
  59.  
  60. .commentbody {
  61. border-top: 1px dotted #ccc;
  62. }
  63.  
  64. /*gray box*/
  65. .submitcomment, #submitcomment, #currentcomments, #rating, .textad {
  66. background-color: #F5F5F5;
  67. border: 1px dotted #ccc;
  68. padding: 5px;
  69. padding: 5px;
  70. margin: 20px 0px 0px 0px;
  71. }
  72.  
  73.  
  74. /*FORMS
  75. *------------------------------------*/
  76.  
  77. .form {
  78. background-color: #FAFAFA;
  79. border: solid 1px #C6C6C6;
  80. padding: 2px;
  81. }
  82.  
  83. .formtext {
  84. background-color: #FAFAFA;
  85. border: solid 1px #C6C6C6;
  86. padding: 2px;
  87. border-bottom: 1px dotted #ccc
  88. }
  89.  
  90. .form:hover, .formtext:hover {
  91. background: white;
  92. }
  93.  
  94. .form:focus, .formtext:focus {
  95. background: white;
  96. border: solid 1px #000000;
  97. }
  98.  
  99. .submit {
  100. background-color: #D3D3D3;
  101. border: solid 1px #C6C6C6;
  102. border-right: solid 1px #9A9A9A;
  103. border-bottom: solid 1px #9A9A9A;
  104. }
  105.  
  106. .submit:hover, .submit:focus {
  107. background: #EDEDED;
  108. }
  109. </style>
  110.  
  111.  
  112. ";
  113. //fetch all comments from database where the tutorial number is the one you are asking for
  114. $commentquery = mysql_query("SELECT * FROM comments WHERE tutorialid='$tutid' ORDER BY date DESC") or die(mysql_error());
  115. //find the number of comments
  116. $commentNum = mysql_num_rows($commentquery);
  117. //create a headline
  118. echo "<div id=\"currentcomments\" class=\"submitcomment\"><h3 class=\"formtitle\">Current Comments</h3>\n";
  119. echo $commentNum . " comments so far (<a href=\"#post\">post your own</a>)\n";
  120. //for each comment in the database in the right category number...
  121. while($commentrow = mysql_fetch_row($commentquery)){
  122. //for security, parse through the bbcode script
  123. //the number corresponds to the column (the message is always stored in column 4
  124. //COUTING STARTS at 0!!!
  125. $commentbb = BBCode($commentrow[4]);
  126. //create the right date format
  127. $commentDate = formatDate($commentrow[6]);
  128.  
  129. echo "<div class=\"commentbody\" id=\"$commentrow[0]\">\n
  130. <p>$commentbb</p>\n
  131. <p class=\"postedby\">Posted by ";
  132. if($commentrow[3]){
  133. echo "<a href=\"$commentrow[3]\">$commentrow[2]</a> ";
  134. } else {
  135. echo "$commentrow[2] ";
  136. }
  137. echo "on $commentDate | #$commentrow[0]</p>\n
  138. \n</div>";
  139.  
  140. }
  141. echo "</div>";
  142. }
  143.  
  144. function submitComments($tutid2,$tuturl){
  145. //a javascript script to make sure all the required fields are filled in
  146. ?>
  147. <script language="javascript">
  148.  
  149. function form_Validator(form)
  150. {
  151.  
  152. if (form.message.value == "")
  153. {
  154. alert("Please enter your message.");
  155. form.message.focus();
  156. return (false);
  157. }
  158.  
  159. return (true);
  160. }
  161. //-->
  162. </script>
  163. <?php
  164. //create the form to submit comments
  165. //you can add more fields, but make sure you add them to the db table and the page, submitcomment.php
  166. echo "
  167. <a name=\"post\">
  168. <div id=\"submitcomment\" class=\"submitcomment\">
  169. <form name=\"submitcomment\" method=\"post\" action=\"submitcomment.php\" onSubmit=\" return form_Validator(this)\">
  170. <table width=\"100%\">
  171. <tr>
  172. <th colspan=\"2\"><h3 class=\"formtitle\">Leave your comment:</h3></th>
  173. </tr>
  174.  
  175. <tr valign=\"top\">
  176. <th scope=\"row\"><p class=\"req\">Comments:</p><br /></th>
  177. <td><textarea class=\"form\" tabindex=\"4\" id=\"message\" name=\"message\" rows=\"1\" cols=\"5\"></textarea></td>
  178. </tr>
  179.  
  180. <tr>
  181. <td>&nbsp;</td>
  182. <td><input type=\"submit\" name=\"post\" class=\"submit\" value=\"Submit Comment\" /><br />
  183. <p>Do not submit false alliance codes. If you find any false codes email worldwarallies@gmail.com</p>
  184.  
  185. </td>
  186. </tr>
  187. </table>
  188. <input type=\"hidden\" name=\"tuturl\" value=\"$tuturl\" />
  189. <input type=\"hidden\" name=\"tutid2\" value=\"$tutid2\" />
  190. </form>
  191.  
  192.  
  193. </div>
  194. ";
  195. }
  196. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement