0

I'm trying to insert multiple rows but I continue getting an sqlerror and cannot for the life of me figure out why.

    echo '"'.$thequery.'"';
    $sql = mysql_query($thequery) or die(mysql_error());
    return "SUCCESS";

$thequery gets printed out as: "INSERT INTO thistable (rank, change, reqID, vanID) VALUES (1,'PICKUP',28,1),(2,'PICKUP',29,1),(3,'DROPOFF',28,1),(4,'DROPOFF',29,1)"

and the 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 'change, reqID, vanID) VALUES (1,'PICKUP',28,1),(2,'PICKUP',29,1),(3,'DROPOFF',28' at line 1

Thanks in advanced.

y3di
  • 673
  • 2
  • 8
  • 13

1 Answers1

1

CHANGE is a reserved word in MySQL. Rename the column or enclose the identifier in backticks.

Besides, you seem to have a typo in the VALUES part: in (1,'PICKUP,'28,1),(2,'PICKUP,'29,1),, the ,' should be ',.

glglgl
  • 89,107
  • 13
  • 149
  • 217
  • I fixed the apostrophe error and it didn't help. but i did change change to thistable.change and it worked, many thanks! What do you mean my backtick tho? Would it just be 'change? – y3di Aug 26 '11 at 05:54
  • No, ' is no backtick. ` is one. You would write `\`change\``. – glglgl Aug 26 '11 at 05:56