Expand|Select|Wrap|Line Numbers
- <html>
- <?php
- class formValidation{
- function checkLength($string, $min, $max, $awnser) {
- $length = strlen($string);
- if($length < $min) {
- die("The $awnser is to short");
- }
- if($length >$max) {
- die("The $awnser is to long");
- }
- }
- }
- //////////////////////////////////////////////////////////////////////////
- include('loginSQL.php');
- $connection = mysql_connect($db_host, $db_username, $db_password);
- if(!connection){
- die ("Could not connect to the database:<br>");
- };
- $select = mysql_select_db($db_database);
- if(!$select){
- die("Could not select the database.<br./>");
- };
- $query = "SELECT * FROM comments";
- $result = mysql_query($query);
- if(!$result){
- die("Could not execute the query <br>".mysql_error());
- };
- if(!is_null($_POST['name'])) {
- formValidation::checkLength($_POST['name'],2,50,name);
- $name = $_POST['name'];
- formValidation::checkLength($_POST['comment'],0,500,comment);
- $comment = $_POST['comment'];
- $date = date("F/j/Y");
- $time = date("g:i:A");
- $query = "INSERT INTO comments VALUES ('$name', '$comment', '$time', '$date');";
- $result = mysql_query($query);
- if(!$result){
- die("Could not insert the comment".mysql_error());
- };
- $query = "SELECT * FROM comments";
- $result = mysql_query($query);
- if(!$result){
- die("Could not execute the query <br>".mysql_error());
- };
- };
- $_POST['name'] = NULL;
- ?>
- <font size = "5" color = "Grey"> Comments </font>
- <hr>
- <?php
- while ($result_row = mysql_fetch_row(($result))){
- echo $result_row[0];
- echo ' Left this comment on ';
- echo $result_row[3];
- echo ' at ';
- echo $result_row[2];
- echo '<br>';
- echo $result_row[1];
- echo '<hr>';
- };
- ?>
- <hr>
- <font size ="5" color = "Grey"> Leave A Comment!</font><br>
- <form action = "comments.php" method = "post">
- Name<br>
- <input = "text" name = "name"><br>
- <textarea cols = "40" rows = "5" name = "comment">
- Type your comment here!
- </textarea><br>
- <input type = "submit">
- </form>
- <hr>
- </html>
- <!--
- Problems
- When Pressing The Refresh Button It Posts The Comment Again
- -->
It also does not do the date correctly but I can fix that.
Thanks,
Matt