$fileType = $_FILES['photoFilename']["type"]; $fullPath = $imagesDir . $photoName; // Save the image to the relevant directory $targetPath = $imagesDir . basename($_FILES['photoFilename']['name']); if (move_uploaded_file($tmpName, $targetPath) || empty($_POST['photoFilename'])) { // If the picture is empty, point to a default image if ($_FILES['photoFilename']['error'] == 4) { $photoName = "empty"; } // Get the slug for this page $postSlug = slug($postTitle); // Insert the blog into the database $stmt = $db->prepare('INSERT INTO blog_posts (postTitle, postSlug, postDesc,postCont,postDate,postMember, postImage) VALUES (:postTitle, :postSlug, :postDesc, :postCont, :postDate, :postMember, :postImage)'); $stmt->execute(array(':postTitle' => $postTitle, ':postSlug' => $postSlug, ':postDesc' => $postDesc, ':postCont' => $postCont, ':postDate' => date('Y-m-d H:i:s'), ':postMember' => $_SESSION['username'], ':postImage' => $photoName)); // Lastly, create a thumbnail of the image - or resize it. $blog->create_thumbnail($photoName, "thumb_" . $photoName, 600, 400); // Get the ID of the last row that was inserted $postID = $db->lastInsertId(); //add category $stmt = $db->prepare('INSERT INTO blog_post_cats (postID, catID) VALUES (:postID,:catID)'); $stmt->execute(array(':postID' => $postID, ':catID' => $catID)); //redirect to index page header('Location: adminindex.php?action=posted'); exit; } else { // The image has failed to be saved echo '<script type="text/javascript">sweetAlert("Error",'; echo '"There has been a problem saving the image."'; echo ' , "error");</script>'; } } else {