注意:使用未定义的常数日期 - 假设'日期'在 第14行的C:\ xampp \ htdocs \ cms \ admin \ includes \ add_post.php
警告:非法字符串偏移' d-m-y'在第14行的C:\ xampp \ htdocs \ cms \ admin \ includes \ add_post.php
警告:mysqli_error()预计在第23行C:\ xampp \ htdocs \ cms \ admin \ includes \ add_post.php中给出1个参数,2 QUERY FAILED。
if (isset($_POST['create_post'])){
$post_title = $_POST['title'];
$post_author = $_POST['author'];
$post_category_id= $_POST['post_category_id'];
$post_status = $_POST['post_status'];
$post_image = $_FILES['image']['name'];
$post_image_temp = $_FILES['image'] ['tmp_name'];
$post_tags = $_POST['post_tags'];
$post_content = $_POST['post_content'];
$post_date = date['d-m-y'];
$post_comment_count = 4;
move_uploaded_file($post_image_temp, "../images/$post_image");
$query ="INSERT INTO posts(post_category_id, post_title, post_author, post_date, post_image, post_content, post_tags, post_comment_count, post_status) ";
$query .="VALUES ({$post_category_id}, '{$post_title}', '{$post_author}',getDate() , '{$post_image}', '{$post_content}', '{$post_tags}', '{$post_comment_count}', '{$post_status}') ";
$create_post_query = mysqli_error($connection, $query);
confirmQuery($create_post_query);
}
?>
答案 0 :(得分:1)
<强>的变化:强>
date('d-m-y')
now()
代替getDate()
mysqli_query($myConnection, $sqlCommand) or die (mysqli_error($myConnection));
正确的代码:
if (isset($_POST['create_post'])){
$post_title = $_POST['title'];
$post_author = $_POST['author'];
$post_category_id= $_POST['post_category_id'];
$post_status = $_POST['post_status'];
$post_image = $_FILES['image']['name'];
$post_image_temp = $_FILES['image'] ['tmp_name'];
$post_tags = $_POST['post_tags'];
$post_content = $_POST['post_content'];
$post_date = date('d-m-y');
$post_comment_count = 4;
move_uploaded_file($post_image_temp, "../images/$post_image");
$query ="INSERT INTO posts(post_category_id, post_title, post_author, post_date, post_image, post_content, post_tags, post_comment_count, post_status) ";
$query .="VALUES ({$post_category_id}, '{$post_title}', '{$post_author}',now() , '{$post_image}', '{$post_content}', '{$post_tags}', '{$post_comment_count}', '{$post_status}') ";
$create_post_query = mysqli_error($connection, $query);
confirmQuery($create_post_query);
}
?>