我已经用数据库制作了一个简单的php cms表单,但是当我想用一些虚拟数据提交表单时,它不能正常工作!我不知道为什么会发生&我还添加了mysqli_error()来获取我所面临的错误类型,但是我只有这样:
您的SQL语法有误;检查与您的MySQL服务器版本相对应的手册以在第2行的“,”,”)’附近使用正确的语法
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 '';
}else{
move_uploaded_file($image_tmp,"post_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')";
$insert_post = mysqli_query($con,$insert_query);
if ($insert_post){
echo '
Post has been added successfully.
';}else{
echo mysqli_error($con);
}
}
}
?>
Insert Post Title | |
Insert Post Author | |
Insert Post Keywords | |
Insert Post Image | |
Insert Post Content | |
如果您分享此问题的解决方案,这对我非常有帮助…谢谢!
解决方法:
您在$post_image之前缺少引号:
,$post_image'
应该:
,'$post_image'
因此,完整的SQL语句变为:
$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 ($post_title=='' or $post_keywords='' or $post_content='' or $post_author=''){
您应该使用double ==而不是=.
标签:php,mysql,forms
来源: https://codeday.me/bug/20191013/1911149.html