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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Workbench中材料库无法更新,如何解决?
  • ¥20 如何推断此服务器配置
  • ¥15 关于github的项目怎么在pycharm上面运行
  • ¥15 内存地址视频流转RTMP
  • ¥100 有偿,谁有移远的EC200S固件和最新的Qflsh工具。
  • ¥15 有没有整苹果智能分拣线上图像数据
  • ¥20 有没有人会这个东西的
  • ¥15 cfx考虑调整“enforce system memory limit”参数的设置
  • ¥30 航迹分离,航迹增强,误差分析
  • ¥15 Chrome Manifest扩展引用Ajax-hook库拦截请求失败