Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Please set the following variables for your MySQL database:
- //Please set the following variables for your MySQL database:
- //it is highly recommended that you restrict access for the user for security reasons
- //it only needs "INSERT" privileges
- $db_hostname = "mysql5.000webhost.com"; //usually "localhost be default"
- $db_username = "a1636860_root"; //your user name
- $db_pass = "dock54"; //the password for your user
- $db_name = "a1636860_wwa"; //the name of the database
- /*MYSQL DATABASE CONNECTION/ TRACKING FUNCTIONS
- --------------------------------------*/
- // connect to database
- $dbh = mysql_connect ($db_hostname, $db_username, $db_pass) or die ('I cannot connect to the database because: ' . mysql_error());
- mysql_select_db ($db_name);
- ?>
- <style type="text/css">
- body {
- font-family: Helvetica, sans-serif;
- font-size: 12px;
- }
- </style>
- //quick script to make the data look nice
- function formatDate($val)
- {
- list($date, $time) = explode(" ", $val);
- list($year, $month, $day) = explode("-", $date);
- list($hour, $minute, $second) = explode (":", $time);
- return date("l, m.j.y @ H:ia", mktime($hour, $minute, $second, $month, $day, $year));
- }
- function getComments($tutid){
- //creates a function that can easily be called from any page
- //create the css code to make the form look good. You can edit this to change colors, etc:
- echo "
- <style>
- /*COMMENTS
- *------------------------------------*/
- .postedby {
- padding: 0 0 0 18px;
- background: url(images/abullet.gif) no-repeat 0 4px;
- }
- h3.formtitle {
- margin : 0px 0px 0px 0px;
- border-bottom: 1px dotted #ccc;
- padding-bottom: 8px;
- }
- .commentbody {
- border-top: 1px dotted #ccc;
- }
- /*gray box*/
- .submitcomment, #submitcomment, #currentcomments, #rating, .textad {
- background-color: #F5F5F5;
- border: 1px dotted #ccc;
- padding: 5px;
- padding: 5px;
- margin: 20px 0px 0px 0px;
- }
- /*FORMS
- *------------------------------------*/
- .form {
- background-color: #FAFAFA;
- border: solid 1px #C6C6C6;
- padding: 2px;
- }
- .formtext {
- background-color: #FAFAFA;
- border: solid 1px #C6C6C6;
- padding: 2px;
- border-bottom: 1px dotted #ccc
- }
- .form:hover, .formtext:hover {
- background: white;
- }
- .form:focus, .formtext:focus {
- background: white;
- border: solid 1px #000000;
- }
- .submit {
- background-color: #D3D3D3;
- border: solid 1px #C6C6C6;
- border-right: solid 1px #9A9A9A;
- border-bottom: solid 1px #9A9A9A;
- }
- .submit:hover, .submit:focus {
- background: #EDEDED;
- }
- </style>
- ";
- //fetch all comments from database where the tutorial number is the one you are asking for
- $commentquery = mysql_query("SELECT * FROM comments WHERE tutorialid='$tutid' ORDER BY date DESC") or die(mysql_error());
- //find the number of comments
- $commentNum = mysql_num_rows($commentquery);
- //create a headline
- echo "<div id=\"currentcomments\" class=\"submitcomment\"><h3 class=\"formtitle\">Current Comments</h3>\n";
- echo $commentNum . " comments so far (<a href=\"#post\">post your own</a>)\n";
- //for each comment in the database in the right category number...
- while($commentrow = mysql_fetch_row($commentquery)){
- //for security, parse through the bbcode script
- //the number corresponds to the column (the message is always stored in column 4
- //COUTING STARTS at 0!!!
- $commentbb = BBCode($commentrow[4]);
- //create the right date format
- $commentDate = formatDate($commentrow[6]);
- echo "<div class=\"commentbody\" id=\"$commentrow[0]\">\n
- <p>$commentbb</p>\n
- <p class=\"postedby\">Posted by ";
- if($commentrow[3]){
- echo "<a href=\"$commentrow[3]\">$commentrow[2]</a> ";
- } else {
- echo "$commentrow[2] ";
- }
- echo "on $commentDate | #$commentrow[0]</p>\n
- \n</div>";
- }
- echo "</div>";
- }
- function submitComments($tutid2,$tuturl){
- //a javascript script to make sure all the required fields are filled in
- ?>
- <script language="javascript">
- function form_Validator(form)
- {
- if (form.message.value == "")
- {
- alert("Please enter your message.");
- form.message.focus();
- return (false);
- }
- return (true);
- }
- //-->
- </script>
- <?php
- //create the form to submit comments
- //you can add more fields, but make sure you add them to the db table and the page, submitcomment.php
- echo "
- <a name=\"post\">
- <div id=\"submitcomment\" class=\"submitcomment\">
- <form name=\"submitcomment\" method=\"post\" action=\"submitcomment.php\" onSubmit=\" return form_Validator(this)\">
- <table width=\"100%\">
- <tr>
- <th colspan=\"2\"><h3 class=\"formtitle\">Leave your comment:</h3></th>
- </tr>
- <tr valign=\"top\">
- <th scope=\"row\"><p class=\"req\">Comments:</p><br /></th>
- <td><textarea class=\"form\" tabindex=\"4\" id=\"message\" name=\"message\" rows=\"1\" cols=\"5\"></textarea></td>
- </tr>
- <tr>
- <td> </td>
- <td><input type=\"submit\" name=\"post\" class=\"submit\" value=\"Submit Comment\" /><br />
- <p>Do not submit false alliance codes. If you find any false codes email worldwarallies@gmail.com</p>
- </td>
- </tr>
- </table>
- <input type=\"hidden\" name=\"tuturl\" value=\"$tuturl\" />
- <input type=\"hidden\" name=\"tutid2\" value=\"$tutid2\" />
- </form>
- </div>
- ";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement