Notice: Undefined index: categoryID in C:\xampp\htdocs\mit\postCategory.php on line 14
I'm having this error in my PHP code below where I'm only getting the categoryID via session and storing it in a index/variable which is $categoryID
and then I called this variable on line 20 where I have my $query. Did I miss something? Thank you for your help!
<?php
session_start();
include "dbconnect.php";
if (!isset($_SESSION['admin'])) {
header("Location:index.php");
}
if (isset($_GET['categoryID'])) {
$_SESSION['postCategory']['categoryID'] = $_GET['categoryID'];
}
if (isset($_POST['update'])) {
$categoryID = $_GET['categoryID'];
$postTitle = $_POST['postTitle'];
$postDesc = $_POST['postDesc'];
$postImage = $_FILES['image']['name'];
$target = "postImage/".basename($postImage);
$query = "UPDATE background SET postTitle = '$postTitle', postDesc = '$postDesc', postImage = '$postImage' WHERE post.categoryID ='$categoryID'";
$result = mysqli_query($con, $query);
if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
$msg = "Image uploaded successfully";
} else {
$msg = "Failed to upload image";
}
}
?>
<form method="post" action="postCategory.php" enctype="multipart/form-data">
<input type="text" name="postTitle" placeholder="Your Post Title">
<br>
<textarea name="postDesc" id="myTextarea">Your Post Description</textarea>
<br>
<input type="file" name="image">
<br>
<button type="submit" class="btn btn-primary" name="update">Post</button>
</form>