<?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))
}
}
?>
它给出了错误,通知未定义:第19行上的类别 和未定义的通知:广告内容描述行, 如何获得定义类别和描述?帮助我如何初始化说明和类别。
答案 0 :(得分:0)
您可以这样做:
if( !empty($_POST['description']) ){
$description = mysqli_real_escape_string($conn, $_POST['description']);
}
else{
$description = '';
}
对未定义的其他索引进行相同的设置。这是因为您的表单未发送此POST数据。