Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>test1</title>
- </head>
- <body>
- <form method="POST">
- <input type="text" name="title" placeholder="Enter Your Heading....." required><br><br>
- <textarea id="textarea" name="content" minlength="5" placeholder="Enter Your Content Here...." required></textarea><br><br><div id="textarea_feedback"></div>
- <input type="text" name="tags" placeholder="Enter Your Tags" required><br><br>
- <input type="submit" name="submit" value="Post"><br><br><br>
- <script>
- $(document).ready(function() {
- $('#textarea').keyup(function() {
- var text_length = $('#textarea').val().length;
- $('#textarea_feedback').html(text_length + ' characters ');
- });
- });
- </script>
- </form>
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "izaya";
- $conn = new mysqli($servername, $username, $password, $dbname);
- function timeago($time_ago)
- {
- $cur_time = time();
- $time_elapsed = $cur_time - $time_ago;
- $sec = $time_elapsed;
- $min = round($time_elapsed / 60);
- $hours = round($time_elapsed / 3600);
- $days = round($time_elapsed / 86400);
- $weeks = round($time_elapsed / 604800);
- $months = round($time_elapsed / 2600640);
- $years = round($time_elapsed / 31207680);
- if ($sec <= 60) {
- echo "$sec Seconds ago";
- }
- else if ($min <= 60) {
- if ($min == 1){
- echo "one minute ago";
- }else {
- echo "$min Minutes ago";
- }
- }
- else if ($hours <= 24) {
- if ($hours == 1) {
- echo "one hour ago";
- }else {
- echo "$hours Hours ago";
- }
- }
- else if ($days <= 7) {
- if ($days == 1) {
- echo "yesterday";
- }else {
- echo "$days Days ago";
- }
- }
- else if ($weeks <= 4.3) {
- if ($weeks == 1) {
- echo "one week ago";
- }else {
- echo "$weeks weeks ago";
- }
- }
- else if ($months <= 12) {
- if ($months == 1) {
- echo "one month ago";
- }else {
- echo "$months Months ago";
- }
- }
- else
- if ($years == 1) {
- echo "one Year ago";
- }else {
- echo "$years Years ago";
- }
- }
- $dat = date("Y-m-d H:i:s");
- $query = "INSERT INTO posts (title,content,tags, tim) VALUES (?,?,?,?)";
- if ($statment = $conn->prepare($query)) {
- $statment->bind_param("ssss" , $_POST['title'], $_POST['content'],$_POST['tags'], $tim = $dat);
- if ($statment->execute()) {
- $take = $conn->query("SELECT title,content,tim FROM posts ORDER BY id");
- $count = $take->num_rows;
- if ($count) {
- while ($print = $take->fetch_assoc()) {
- echo '<br>';
- echo $print['title'];
- echo "<br>";
- echo $print['content'];
- echo "<br>";
- echo $print['tags'];
- echo "<br>";
- $waktu = $print['tim'];
- $time_ago = strtotime($waktu);
- echo timeago($time_ago);
- }
- }
- else {echo "something";}
- }
- }
- else {
- echo "string";
- }
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment