Copy link to clipboard
Copied
Hi,
I have a form that inserts values into a table called group.
my insert code is:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO ``group`` (group_name, group_type, group_summary, group_description, group_website, auto_accept, group_owner, agreed) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['group_name'], "text"),
GetSQLValueString($_POST['group_type'], "text"),
GetSQLValueString($_POST['group_summary'], "text"),
GetSQLValueString($_POST['group_description'], "text"),
GetSQLValueString($_POST['group_website'], "text"),
GetSQLValueString(isset($_POST['auto_accept']) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString($_POST['user_id'], "int"),
GetSQLValueString(isset($_POST['agreed']) ? "true" : "", "defined","'Y'","'N'"));
mysql_select_db($database_db, $db);
$Result1 = mysql_query($insertSQL, $db) or die(mysql_error());
$insertGoTo = "groups.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
I get this error: Incorrect table name ''
Could it be that 'group' is a reserved word in MySQL?
Copy link to clipboard
Copied
Could it be that 'group' is a reserved word in MySQL?
Copy link to clipboard
Copied
As bregent points out, group is a reserved word in MySQL (and almost certainly in all other versions of SQL).
It also helps if you look at your code. To use a reserved word as an identifier (database, column, or table name) in MySQL, you escape it with backticks. Both phpMyAdmin and Dreamweaver try to protect less experienced developers by automatically adding backticks. phpMyAdmin does it for all identifiers. I think Dreamweaver does it only for reserved words.
Now take a look at your code:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO ``group``
(group_name, group_type, group_summary, group_description,
group_website, auto_accept, group_owner, agreed)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",You can see that group has been surrounded by two sets of backticks. I don't know where the second set of backticks has come from, but that's what's causing the problem. Remove the extra set of backticks so you're left with `group`, and it should work.
Better still, rename the table and familiarize yourself with the (big) list of reserved words in MySQL: http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more