2013-09-24 16:08
浏览 29

MYSQL 5.6.12中mysql插入查询中的错误

I tried to use the following code to insert,


mysql_query("insert into $username values('Q3','$op')")
or die(mysql_error());

But I got the following error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'values('Q1','Wrong')' at line 1

Why am I getting this error? How can I fix it?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doujishao8793
    doujishao8793 2013-09-24 16:12

    Your query structure is not making any sense. You're inserting into $username? That's not the name of the table, is it?

    mysql_query("INSERT INTO `tablename` values('Q3','" . mysql_real_escape_string($op) . "')") or die(mysql_error());

    Always be very careful to escape any and all user data being put into your queries, and please, please stop using mysql_query in new code.

    点赞 评论