I am trying to learn some MySQL and PhP and am having trouble using the query() method to update my database.
I can fetch() and display the information, so I know my connection is fine, and I've updated in a similar way previously with no issue. I've also double-checked that I'm sending the correct data types, that my names are correct, and that I'm not going over any character limits, so I'm a little at a loss. I used var_dump to check the result of query and keep getting a false boolean.
<?php
if(isset($_POST["submit"])) {
$title = $_POST["title"];
$category = $_POST["category"];
$image = $_FILES["image"]["name"];
$text = $_POST["text"];
$targetFile = "upload/".basename($image);
//validations
if(empty($title)) {
$_SESSION["errorMessage"] = "A title is required.";
redirect("editPost.php");
} else if (strlen($title) > 49) {
$_SESSION["errorMessage"] = "Post title can not be greater than 50 characters.";
redirect("editPost.php");
} else if (strlen($title) <= 5) {
$_SESSION["errorMessage"] = "Post title must be greater than 5 characters.";
redirect("editPost.php");
} else if (strlen($text) > 9999) {
$_SESSION["errorMessage"] = "Post content must be under 10000 characters.";
redirect("editPost.php");
} else {
$sql = "
UPDATE posts
SET title='$title'
, category='$category'
, image='$image'
post='$text' -- er, something missing here
WHERE id = '$searchQueryParameter'
";
$execute = $connectDB -> query($sql);
var_dump($execute);
move_uploaded_file($_FILES["image"]["tmp_name"], $targetFile);
/* if ($execute) {
$_SESSION["successMessage"] = "Post updated successfully.";
redirect("posts.php");
} else {
$_SESSION["errorMessage"] = "Something went wrong. Please try again.";
redirect("posts.php");
} */
}
}
?>
Any help would be appreciated, thanks!