douliexu5623
2018-08-23 12:50
浏览 73
已采纳

注意:未定义索引:类别和注意:未定义索引:说明[重复]

<?php

session_start();

// initializing variables
$title = "";
$categories = "";
$profile = "";
$description = "";
$errors = array();

// connect to the database
$conn = mysqli_connect("localhost", "root", "", "blogs");

// CREATE BLOGS
if (isset($_POST['blog_submit'])) {
    // receive all input values from the form
    $title = mysqli_real_escape_string($conn, $_POST['title']);
    $categories = mysqli_real_escape_string($conn, $_POST['categories']);
    $profile = mysqli_real_escape_string($conn, $_FILES['profile']['name']);
    $description = mysqli_real_escape_string($conn, $_POST['description']);

    // by adding (array_push()) corresponding error unto $errors array
    if (empty($title)) {
        array_push($errors, "Title is required");
    }
    if (empty($categories)) {
        array_push($errors, "Category is required");
    }
    if (empty($profile)) {
        array_push($errors, "Profile is required");
    }
    if (empty($description)) {
        array_push($errors, "Description is required");
    }
    if (count($errors) == 0) {
        $q2 = "INSERT INTO category (title, categories, profile, description) 
                  VALUES('$title', '$categories','$profile', '$description')";
        mysqli_query($conn, $q2);
        // $q2="INSERT INTO categories (title, categories, profile, description) 
        // VALUES('$title', '$categories','$profile', '$description')";
        // $run=mysqli_query($conn, $q2);
        // while($row=mysqli_fetch_array($run))
    }
}
?>

It gives error that Notice undefined: categories on line 19 and Notice undefined: description line, how to get define categories and description? help me how to get initialize the description and categories.

</div>
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doubaomao9304 2018-08-23 12:53
    已采纳

    You can do this :

    if( !empty($_POST['description']) ){
    $description = mysqli_real_escape_string($conn, $_POST['description']);
    }
    else{
    $description = '';
    }
    

    And make the same for your other index not defined. The reason it's your form doesn't send this POST data.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题