PHP-无法识别的索引变量

时间:2019-03-08 14:18:24

标签: php post get php-mysqlidb

Notice: Undefined index: categoryID in C:\xampp\htdocs\mit\postCategory.php on line 14

我在下面的PHP代码中遇到此错误,在这里我仅通过会话获取categoryID并将其存储在$ categoryID的索引/变量中,然后在第20行调用了此变量,其中有我的$查询。我错过了什么?谢谢您的帮助!

<?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>

0 个答案:

没有答案