lampwins
lampwins

Reputation: 920

what causes the error with this mysql query?

mysql_query ("
  INSERT INTO items 
    (index, name, description, given_by, 
     cost_to_tcs, starting_bid, auction_type) 
  VALUES
    ('{$index_number}','{$name}','{$description}','{$donated_by}',
     NULL,'{$auction_type}','{$starting_bid}')
  ") 
  or die("3: " . mysql_error());

Errors with:

3: 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 ''index', 'name', 'description', 'given_by', 'cost_to_tcs', 'starting_bid', 'auct' at line 1

Thanks for any help.

Upvotes: 2

Views: 118

Answers (2)

xkeshav
xkeshav

Reputation: 54016

index is mysql Reserved keyword, wrap index with (back tick) `` `

INSERT INTO items 
 (`index`, `name`, `description`, `given_by`,
  `cost_to_tcs`, `starting_bid`, `auction_type`) 

Reserve key words

Upvotes: 8

jogesh_pi
jogesh_pi

Reputation: 9782

try like that:

mysql_query ("
INSERT INTO items (
    `index`, 
    `name`, 
    `description`, 
    `given_by`, 
    `cost_to_tcs`, 
    `starting_bid`, 
    `auction_type`) 
VALUES(
    '$index_number',
    '$name',
    '$description',
    '$donated_by',
    NULL,
    '$auction_type',
    '$starting_bid')
") 
or die("3: " . mysql_error());

also make sure to safe the data with mysql_real_escape_string();

Upvotes: 1

Related Questions