unexpected error message in php form (SQL syntax error)

后端 未结 3 1874
野性不改
野性不改 2021-01-24 00:23

I have made a simple php cms form with database but it does not work properly when I want to submit the form with some dummy data! I don\'t know why it happens & also I adde

3条回答
  •  走了就别回头了
    2021-01-24 00:58

    You are missing a quote just before $post_image:

    ,$post_image'
    

    Should be:

    ,'$post_image'
    

    So the complete SQL statement becomes then:

    $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')";
    

    Please note that you are doing assignments in this if:

    if ($post_title=='' or $post_keywords='' or $post_content='' or $post_author=''){
    

    You should be using double == instead of =.

    Finally, your code is vulnerable to SQL injection. So please use prepared statements with parameters.

提交回复
热议问题