Henrikh
Henrikh

Reputation: 168

getting error on inserting

Do you see any problem? I get this error.

$col = 360;
$col1 = 350;

$esim = 0;
$esim1 = 1;

mysql_query("INSERT INTO my_table ($col, $col1) VALUES('$esim', '$esim1')") or die(mysql_error());

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 '360, 350) VALUES('0', '1')' at line 1

Upvotes: 0

Views: 37

Answers (4)

Awlad Liton
Awlad Liton

Reputation: 9351

It is tested it is working :)
you have problem in your column name. it is treated as an integer value not as a column name.

$col = 360;
$col1 = 350;

Can you use backticks in name like :

$col = "`360`";
$col1 = "`350`";

Upvotes: 1

user1844933
user1844933

Reputation: 3417

Try this...

  $col = "`360`";
  $col1 = "`350`";

  $esim = 0;
  $esim1 = 1;

 mysql_query("INSERT INTO my_table ($col, $col1) VALUES('$esim', '$esim1')") or die(mysql_error());

If column name is in number it should be enclosed with ``

Upvotes: 1

db-mobile
db-mobile

Reputation: 326

I guess you are suffering from the same problem as here: Can a number be used to name a MySQL table column?

Put your table and column names into backticks.

Upvotes: 1

GuyT
GuyT

Reputation: 4416

Change 'table' to `table`. The word 'table' is reserved. More info about reserved words: https://drupal.org/node/141051

Identifiers may begin with a digit but unless quoted may not consist solely of digits.(http://dev.mysql.com/doc/refman/5.0/en/identifiers.html)

Upvotes: 1

Related Questions