为什么我的插入查询不起作用?

时间:2017-03-03 11:25:47

标签: php mysql sql

$phone

以下是我正在处理的表单,我收到的错误是

  

查询失败您的SQL语法中有错误;查看与您的MariaDB服务器版本对应的手册,以获得正确的语法,以便在附近使用#39; '','',now(),'','','',& #39; 4','')'在第1行

我根据我检查了我的查询它看起来是正确的

3 个答案:

答案 0 :(得分:0)

你可能在一个php变量中使用了撇号。对从表单获得的每个变量使用mysqli_real_escape_string()函数。你应该总是因为SQL注入而这样做。

答案 1 :(得分:0)

您为这些

使用的列类型是什么

“post_category_id,post_title,post_author,post_date,post_image,post_content,post_tags,post_comment_count,post_status”。

对字符串也使用mysqli_real_escape_string(),您需要将活动连接作为第一个参数传递。

答案 2 :(得分:0)

move_uploaded_file($post_image_temp, "../image/ $post_image");

$query = "INSERT INTO posts(post_category_id, post_title, post_author, post_date, post_image, post_content, post_tags, post_comment_count, post_status) ";

 $query .= "Values ( $post_category_id, '$post_title', '$post_author','".now()."', '$post_image', '$post_content', '$post_tags', '$post_comment_count', '$post_status') ";

$connet_query_post = mysqli_query($connection, $query);

          if(!$connet_query_post)
            {

                die("Query Failed" . mysqli_error($connection));
            }

now()是您不能将其用作字符串的功能。

Query FailedYou have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' '', '',now(), '', '', '', '4', '')' at line 1

在你的错误中你可以看到now()instated of now()在string

中应该有一些值
相关问题