Here's my code what i've been trying to do. I've tried to upload(insert) image into a folder and a database, but I'm unable to Insert an Image into a folder and a database. Please help me if you see some mistake in my code. It is inserting Title, Date, Content but no Image.
if(isset($_POST['submit'])){
$title = $connection->real_escape_string($_POST['title']);
$datum = $connection->real_escape_string($_POST['datum']);
$content = $connection->real_escape_string($_POST['editor']);
$image = $_FILES['image'];
$imageName = $_FILES['image']['name'];
$imageTmpName = $_FILES['image']['tmp_name'];
$imageError = $_FILES['image']['error'];
$imageType = $_FILES['image']['type'];
$imageExt = explode('.', $imageName);
$imageActualExt = strtolower(end($imageExt));
$allowed = array('jpg', 'jpeg', 'png');
if(in_array($imageActualExt, $allowed)) {
if($imageError === 0) {
$imageNameNew = uniqid('', true).".".$imageActualExt;
$imageDestination = 'images/'.$imageNameNew;
move_uploaded_file($imageTmpName, $imageDestination);
$sql = "INSERT INTO `articles` (`image`) VALUES ('$imageNameNew')";
$qry = mysqli_query($connection, $sql);
echo "Image was uploaded";
}
} else {
echo "Cannot upload an image";
}
$sql = "INSERT INTO `articles` (`title`, `datum`, `content`) VALUES ('$title', '$datum', '$content')";
if ($connection->query($sql) === true){
echo '<script language="javascript">';
echo 'alert("Post successfully uploaded")';
echo '</script>';
}else {
die("mistacke with uploading a post".mysqli_connect_error());
};
header('location: Admin-clanky-Sprava-clanku.php');
};
<form method="post" action="Admin-clanky-vytvorit-clanek.php" enctype=”multipart/form-data”>
<div class="inputs">
<input type="file" name="image" src="" alt="">
</div>
<div>
<input type="submit" name="submit" value="Přidat článek">
</div>