Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

insert problem Incorrect table name '' php/mysql

Participant ,
Mar 26, 2010 Mar 26, 2010

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 ''

TOPICS
Server side applications
6.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 26, 2010 Mar 26, 2010

Could it be that 'group' is a reserved word in MySQL?


Translate
LEGEND ,
Mar 26, 2010 Mar 26, 2010

Could it be that 'group' is a reserved word in MySQL?


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 29, 2010 Mar 29, 2010
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines