php sql错误,php形式的意外错误消息(SQL语法错误)

我已经用数据库制作了一个简单的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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值