【发布时间】:2015-02-01 00:23:32
【问题描述】:
我想在 PHP 和 MySQL 中制作一个 CMS,但我收到错误未定义:索引关键字,我在做什么错?
<?php
include("includes/connect.php");
if (isset($_POST['submit'])){
$post_title = $_POST['title'];
$post_date = date('d-m-y');
$post_author = $_POST['author'];
$post_keywords = $_POST['keywords'];
$post_content = $_POST['content'];
$post_image = $_FILES['image'] ['name'];
$image_tmp = $_FILES['image'] ['tmp_name'];
if($post_title=='' or $post_keywords=='' or $post_content=='' or $post_author==''){
echo "<script>alert('any of the field is empty')</script>";
exit();
}
else{
move_uploaded_file($image_tmp, "images/$post_image");
$insert_query = "insert into posts (post_title,post_date,post_author,post_image,post_keywords,post_content) values ('$post_title','$post_date','$post_author','$post_image', '$post_keywords', $post_content)";
if (mysql_query($insert_query)) {
echo "<center><h1>Post Published succesfully!</h1></center>";
}
}
}
【问题讨论】:
-
请向我们展示您的 html 表单。这也意味着
$_POST['keywords']没有设置! -
检查您的表单元素是否包含名称属性。如果没有,那就有问题了。
-
旁注:
'$post_keywords', $post_content-$post_content代表一个字符串;引用它。
标签: php mysql database content-management-system