unexpected error message in php form (SQL syntax error)

后端 未结 3 1873
野性不改
野性不改 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 01:00

    Changes

    1. Use empty for check empty variable
    2. Use || instead of or
    3. Check validation for what you are doing. (move_uploaded_file)
    4. Be careful with quotes ($post_image') - This is the bug in your code
    5. Enhance mysqli_error (if (!$insert_post){)

    Code

    alert("Some fields are missing")';
            }
            else
            {
                if (!move_uploaded_file($image_tmp,"post_images/$post_image")) {
                    echo "Move Failed";
                }
                else
                {
                    $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 mysqli_error($con);
                    }
                    else
                    {
                        echo '

    Post has been added successfully.

    '; } } } } ?>

提交回复
热议问题