解析错误:语法错误,意外',',期待::(T_PAAMAYIM_NEKUDOTAYIM)

时间:2018-04-15 15:35:43

标签: php mysqli

这是我的代码,我收到了这个错误:

  

解析错误:语法错误,意外',',期待::(T_PAAMAYIM_NEKUDOTAYIM)在第68行的E:\ xampp \ htdocs \ cms \ admin \ submit_post.php

    <?php
    if(isset($_POST['add_post'])) {
        $s_posts_title = $_POST['s_post_title'];
        $s_posts_author = $_POST['s_post_author'];
        $s_posts_id = $_POST['s_post_id'];
        $s_posts_tags = $_POST['s_post_tag'];
        $s_posts_image = $_FILES['image']['name'];
        $s_posts_image_temp = $_FILES['image']['tmp_name'];
        $s_posts_content = $_POST['s_post_content'];
        $s_posts_date = date('d-m-y');
        $s_posts_comment = 4;

        move_uploaded_file($s_posts_temp,"cms/admin/images/$s_posts_image");

        if(empty($s_posts_title)) {
            echo "enter name!";
        } else if (empty($s_posts_author)) {
            echo "author name!";
        } else {
            $query = "INSERT INTO posts(post_title,post_id,post_content,post_author,post_date,post_image,post_comment_count,post_tag) ";

/* error from this line line 68 ( query .= VALUES ) */

            $query .= "VALUES('{$s_posts_title}',{$s_posts,id},'{$s_posts_content}','{$s_posts_author}',now(),'{$s_posts_image}','{$s_posts_comment}','{$s_posts_tags}' ) ";
            $connection = mysqli_connect('localhost','root','','cms');
            $result_post = mysqli_query($connection,$query);
            if(!result_post) {
                echo mysqli_error($connection);
            }
        }
    }
    ?>

如果有人帮助解决这个问题,我们将不胜感激。感谢lott !!

1 个答案:

答案 0 :(得分:1)

你用逗号代替下划线:

$query .= "VALUES('{$s_posts_title}',{$s_posts,id},'{$s_posts_content}','{$s_posts_author}',now(),'{$s_posts_image}','{$s_posts_comment}','{$s_posts_tags}' ) ";
                                          here^

应该是

$query .= "VALUES('{$s_posts_title}',{$s_posts_id},'{$s_posts_content}','{$s_posts_author}',now(),'{$s_posts_image}','{$s_posts_comment}','{$s_posts_tags}' ) ";

检查第二个值。您的代码易受SQL注入攻击。