0

$query = "INSERT INTO $stats_table_name (name, name_ID, anz_aufruf) VALUES ($plan_name, $plan_nr, $anz)"; echo "<br />".$query."<br />"; if (!mysql_query($query) && !$error) { die (mysql_error()); }

mysql-error tells me:

INSERT INTO 'p_stats' ('name', 'name_ID', 'anz_aufruf') VALUES ('Laptop 1', '1', '95')
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 ''p_stats' ('name', 'name_ID', 'anz_aufruf') VALUES ('Laptop 1', '1', '95')' at line 1

Where is the code wrong here?

Kermit
  • 33,827
  • 13
  • 85
  • 121

3 Answers3

3

the error is the wrapping of single quotes around table name.

Table names as well as column names are identifiers. They should be wrap if a name is a reserved keyword with backtick (optional if not). Single quotes are for string literal.

Community
  • 1
  • 1
John Woo
  • 258,903
  • 69
  • 498
  • 492
0

Use this.

$query = "INSERT INTO $stats_table_name (name, name_ID, anz_aufruf) 
          VALUES ('".$plan_name."', '".$plan_nr."', '".$anz."')";
Amal Murali
  • 75,622
  • 18
  • 128
  • 150
Bharat Chodvadiya
  • 1,644
  • 4
  • 20
  • 31
-1
$query = "INSERT INTO $stats_table_name (name, name_ID, anz_aufruf) 
          VALUES ('".$plan_name."', '".$plan_nr."', '".$anz."')";
Yasin Patel
  • 5,624
  • 8
  • 31
  • 53
Query
  • 1