<?php include("includes/db.php"); include("includes/auth.php");

if($_POST){
  $title=$_POST['title'];
  $body=$_POST['body'];
  $img="uploads/".time().$_FILES['image']['name'];
  move_uploaded_file($_FILES['image']['tmp_name'],$img);

  $conn->query("INSERT INTO articles(title,body,image) 
  VALUES('$title','$body','$img')");
}

$res=$conn->query("SELECT * FROM articles");
?>
<form method="post" enctype="multipart/form-data">
<input name="title" placeholder="Title"><br>
<textarea name="body"></textarea><br>
<input type="file" name="image"><br>
<button>Publish</button>
</form>

<?php while($a=$res->fetch_assoc()): ?>
<h3><?= $a['title'] ?></h3>
<img src="<?= $a['image'] ?>" width=200>
<p><?= $a['body'] ?></p>
<hr>
<?php endwhile; ?>
