i want to show the image before inserting it to database after selecting an image from file, i want the image to show in the page. Can someone help me? im new to php and html and starting learn it. And if u know what will do can u explain it to me.
here is my php code.
<?php
session_start();
if(isset($_SESSION['username'])){
    include_once('connection.php');
    $username = ucfirst($_SESSION['username']);
    if(isset($_POST['submit'])){
        $title = $_POST['title'];
        $date = $_POST['date'];
        $content = $_POST['content'];
        $file=$_FILES['image']['tmp_name'];
        $image= addslashes(file_get_contents($_FILES['image']['tmp_name']));
        $image_name= addslashes($_FILES['image']['name']);
        move_uploaded_file($_FILES["image"]["tmp_name"],"img/" . $_FILES["image"]["name"]);
        $newsimage="img/" . $_FILES["image"]["name"];
        if(empty($title)){
            echo "Please enter a title";
        }
        else if(empty($date)){
            echo "Please enter a date";
        }
        else if(empty($content)){
            echo "Please enter content";
        }
        else{
        $sql ="INSERT into news (news_title, news_date, news_content, news_image) VALUES ('$title', '$date', '$content', '$newsimage')";
        mysqli_query($con, $sql);
        echo "news entry posted";
        }
    }
}
else{
    header('Location: login.php');
    die();
}
if(isset($_POST['image'])){
}
?>
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
    <h1>Welcome, <?php echo $_SESSION['username']; ?>!</h1>
    <form method="post" action ="admin.php" enctype="multipart/form-data">
        Title<input type ="text" name ="title" /><br>
        Date<input type ="text" name="date" /><br>
        Content<textarea name="content"></textarea>
        <input type="submit" name="submit" value="Post News Entry" />
        <input class="form-control" id="image" name="image" type="file" onchange='AlertFilesize();'/>
    </form>
</body>
</html>
 
     
     
    