Untitled

 avatar
unknown
php
2 years ago
2.1 kB
6
Indexable
<?php require "../includes/header.php";
require "../config/config.php"; ?>

<?php

    if(isset($_POST['submit'])){
        if(empty($_POST['title']) OR empty($_POST['subtitle']) OR
         empty($_POST['body'])){
            echo 'input can not be empty';
        }else{

            $title = $_POST['title'];
            $subtitle = $_POST['subtitle'];
            $body = $_POST['body'];
            $img = $_FILES['img']['name'];
            $user_id = $_SESSION['user_id'];



            $dir = 'images/' .basename($img);

            $insert = $conn->prepare("INSERT INTO posts (title, subtitle, body, img, user_id)
            VALUES (:title, :subtitle, :body:, :img, :user_id)");

            $insert->execute([
                ':title' => $title,
                ':subtitle' => $subtitle,
                ':body' => $body,
                ':img' => $img,
                ':user_id' => $user_id

            ]);


            if(move_uploaded_file($files['img']['imp_name'], $dir)){
                //echo "done";
                header('location: http://localhost/Blog/posts/index.php');
            }


        }
    }


?>



<form method="POST" action="create.php" enctype="multipart/form-data">
    <!-- Email input -->
    <div class="form-outline mb-4">
        <input type="text" name="email" id="form2Example1" class="form-control" placeholder="title" />

    </div>

    <div class="form-outline mb-4">
        <input type="text" name="email" id="form2Example1" class="form-control" placeholder="subtitle" />
    </div>

    <div class="form-outline mb-4">
        <textarea type="text" name="email" id="form2Example1" class="form-control" placeholder="body"
            rows="8"></textarea>
    </div>


    <div class="form-outline mb-4">
        <input type="file" name="email" id="form2Example1" class="form-control" placeholder="image" />
    </div>


    <!-- Submit button -->
    <button type="submit" name="submit" class="btn btn-primary  mb-4 text-center">create</button>


</form>



<? require "includes/footer.php"; ?>
Editor is loading...