0

I am using an custom CMS and trying to insert the value

The result query works well but the result2 query starts giving an error

Even i tried adding that in same query but that still gives me the same error

            $sname=addslashes($_POST['sname']);               
            $descr=mysql_real_escape_string($_POST['descr']);
            $eve_format=mysql_real_escape_string($_POST['eve_format']);
            $name=mysql_real_escape_string($_POST['name']);
            $pbm=mysql_real_escape_string($_POST['pbmstat']);
             $group=$_POST['group'];
            $feat_img=mysql_real_escape_string($_POST['feat_img']);
        $query="INSERT INTO events (descr,name,eve_format,prize1,prize2,eve_sname) VALUES ('".$descr."','".$name."','".$eve_format."','".$prize1."','".$prize2."','".$sname."')";
        $result=mysql_query($query) or die(mysql_error());
        $qry2="INSERT INTO events (group) VALUES ('".$group."')";
        $result2=mysql_query($qry2) or die(mysql_error());

The error i am getting is

 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 'group) VALUES ('1')' at line 1

I am unable to figure whats wrong over there

I don't think i have any syntax error over there

Vaibhav Bhanushali
  • 643
  • 3
  • 12
  • 32

2 Answers2

3

Your hint is already on the MYSQL ERROR highlighted.

right syntax to use near 'group) 

Because group is a mysql reserved word.

You need to wrap it with backticks

`group`

Obligatory Note:

Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Ref: https://stackoverflow.com/a/12860140/3859027

Community
  • 1
  • 1
Kevin
  • 41,694
  • 12
  • 53
  • 70
1

group is MySQL reserved keyword.

http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

Either add a back tick against it group

OR

add DB Name before it

e.g.

TABLE_NAME.group

But, the best way if possible is to rename group to something that is not a MySQL reserved keyword.

Pupil
  • 23,834
  • 6
  • 44
  • 66