Advertisement
Guest User

Untitled

a guest
Jul 30th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. <?php
  2.  
  3. $servername = "localhost";
  4. $username = "root";
  5. $password = "";
  6. $dbname = "ispovesti";
  7. // Create connection
  8. $conn = mysqli_connect($servername, $username, $password, $dbname);
  9.  
  10. // Check connection
  11. if (!$conn) {
  12. die("Connection failed: " . mysqli_connect_error());
  13. }
  14. if(isset($_POST['text'])){
  15. $content= $_POST['text'];
  16. /*$post_date= date('l');*/
  17. $post_date= date("h:i:s");
  18.  
  19. }
  20. $sql = "INSERT INTO posts (post_content, post_date)
  21. VALUES ('$content', '$post_date')";
  22.  
  23. if (!mysqli_query($conn, $sql)) {
  24. echo "Error: " . $sql . "<br>" . mysqli_error($conn);
  25. }
  26. function insertPosts(){
  27. if($_POST['sub']!==NULL){
  28. $text= addslashes($_POST['text']);
  29. global $conn;
  30. $get_posts= "SELECT * FROM posts";
  31. $run_posts= mysqli_query($conn, $get_posts);
  32. while ($row_posts= mysqli_fetch_array($run_posts)) {
  33. $post_content= $row_posts['post_content'];
  34. }
  35.  
  36. if($text==''){
  37. echo "<h4>Greska. Molimo vas unesite tekst.</h4>";
  38. }
  39. elseif($text==$post_content){
  40. echo "Greska, ispovest vec postoji.";
  41. }
  42. else{
  43. echo "
  44. <div class='container'>
  45. <h5>Successfully added</h5>
  46. </div><br>
  47. ";
  48. }
  49. }
  50.  
  51. }
  52.  
  53. function get_posts(){
  54. global $conn;
  55. $get_posts= "SELECT * FROM posts /*ORDER BY DESC LIMIT */";
  56. $run_posts= mysqli_query($conn, $get_posts);
  57. while ($row_posts= mysqli_fetch_array($run_posts)) {
  58. $post_id= $row_posts['post_id'];
  59. $post_content= $row_posts['post_content'];
  60. $post_date= $row_posts['post_date'];
  61.  
  62. echo "
  63. <div id='post' class=''>
  64. <p class='pull-left'>$post_id</p>
  65. <p>$post_content</p>
  66. <p class='pull-right'>$post_date</p>
  67.  
  68. </div><br>
  69. ";
  70. }
  71. }
  72. header('Location:');
  73. ?>
  74. <!DOCTYPE>
  75. <html>
  76. <head>
  77. <title>Ispovesti </title>
  78. <meta charset="utf-8">
  79. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  80. <meta name="viewport" content="width=device-width, initial-scale=1">
  81. <link rel="stylesheet" href="css/bootstrap.css">
  82. <link href="css/style.css" rel="stylesheet">
  83. </head>
  84. <body>
  85. <nav class="navbar navbar-default navbar-fixed-top">
  86. <div class="container">
  87.  
  88. </div>
  89. </nav>
  90. <section id="main">
  91. <div class="container">
  92. <div class="col-md-4 col-md-offset-4">
  93. <form method="post" id="form1">
  94. <textarea id='text' name="text" placeholder="Ispovedi se"></textarea><br>
  95. <button class="btn btn-primary" id="btn" type="submit" name="sub">Objavi</button>
  96. </form>
  97. <?php insertPosts(); ?>
  98. <?php get_posts();?>
  99. </div>
  100. </div>
  101. </section>
  102. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  103. <script type="text/javascript" src="js/bootstrap.min.js"></script>
  104. </body>
  105. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement