Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "ispovesti";
- // Create connection
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- // Check connection
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- }
- if(isset($_POST['text'])){
- $content= $_POST['text'];
- /*$post_date= date('l');*/
- $post_date= date("h:i:s");
- }
- $sql = "INSERT INTO posts (post_content, post_date)
- VALUES ('$content', '$post_date')";
- if (!mysqli_query($conn, $sql)) {
- echo "Error: " . $sql . "<br>" . mysqli_error($conn);
- }
- function insertPosts(){
- if($_POST['sub']!==NULL){
- $text= addslashes($_POST['text']);
- global $conn;
- $get_posts= "SELECT * FROM posts";
- $run_posts= mysqli_query($conn, $get_posts);
- while ($row_posts= mysqli_fetch_array($run_posts)) {
- $post_content= $row_posts['post_content'];
- }
- if($text==''){
- echo "<h4>Greska. Molimo vas unesite tekst.</h4>";
- }
- elseif($text==$post_content){
- echo "Greska, ispovest vec postoji.";
- }
- else{
- echo "
- <div class='container'>
- <h5>Successfully added</h5>
- </div><br>
- ";
- }
- }
- }
- function get_posts(){
- global $conn;
- $get_posts= "SELECT * FROM posts /*ORDER BY DESC LIMIT */";
- $run_posts= mysqli_query($conn, $get_posts);
- while ($row_posts= mysqli_fetch_array($run_posts)) {
- $post_id= $row_posts['post_id'];
- $post_content= $row_posts['post_content'];
- $post_date= $row_posts['post_date'];
- echo "
- <div id='post' class=''>
- <p class='pull-left'>$post_id</p>
- <p>$post_content</p>
- <p class='pull-right'>$post_date</p>
- </div><br>
- ";
- }
- }
- header('Location:');
- ?>
- <!DOCTYPE>
- <html>
- <head>
- <title>Ispovesti </title>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="css/bootstrap.css">
- <link href="css/style.css" rel="stylesheet">
- </head>
- <body>
- <nav class="navbar navbar-default navbar-fixed-top">
- <div class="container">
- </div>
- </nav>
- <section id="main">
- <div class="container">
- <div class="col-md-4 col-md-offset-4">
- <form method="post" id="form1">
- <textarea id='text' name="text" placeholder="Ispovedi se"></textarea><br>
- <button class="btn btn-primary" id="btn" type="submit" name="sub">Objavi</button>
- </form>
- <?php insertPosts(); ?>
- <?php get_posts();?>
- </div>
- </div>
- </section>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
- <script type="text/javascript" src="js/bootstrap.min.js"></script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement