0
mysql_query("INSERT INTO group (name, des, tags, creator, cdate) VALUES ('$gname', '$gdes', '$gtags', '$creator', '$date')") or die (mysql_error());

I keep getting a syntax error... i've been using the same method forever, whats wrong with it?

the variables:

$gname = $_POST['gname'];
$gdes = $_POST['gdes'];
$gtags = $_POST['gtags'];
$date = time();
$creator = $_SESSION['username'];
Alex
  • 122
  • 9
  • possible duplicate of [Syntax error due to using a reserved word as a table or column name in MySQL](http://stackoverflow.com/questions/23446377/syntax-error-due-to-using-a-reserved-word-as-a-table-or-column-name-in-mysql) – Ian Ringrose May 06 '14 at 10:05

3 Answers3

5

Post the Syntax Error....!!

But Ill have a guess, group is a mysql keyword. Try:

mysql_query("INSERT INTO `group` (name, des, tags, creator, cdate) VALUES ('$gname', '$gdes', '$gtags', '$creator', '$date')") or die (mysql_error())

Note the backticks around the group table name. This allows you to use mysql reserved keywords as your own table names

cowls
  • 24,013
  • 8
  • 48
  • 78
0
 mysql_query("INSERT INTO group (name, des, tags, creator, cdate) VALUES ('$gname',
   '$gdes', '$gtags', '$creator', '$date')", $connect) or die (mysql_error());

or

$sql="insert sql";
$result=mysql_query($sql,$connect)or die ("cannot insert".mysql_error());
Note: $connect means connection string

Try this you just copy the sql and direct enter to db, if it works that mean error not in ur sql

Charles
  • 50,943
  • 13
  • 104
  • 142
Anand Somasekhar
  • 596
  • 1
  • 11
  • 20
0

you are using a keyword group, which is a reserved MySQL keyword, I am sure this is the cause of your problem, Either change the name of your table or use it as follow... group

Charles
  • 50,943
  • 13
  • 104
  • 142
Amrinder Singh
  • 5,300
  • 12
  • 46
  • 88