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.

1
  • @Justin Casing is not a reason for syntax errors. Commented Aug 26, 2011 at 5:50

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

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?
No, ' is no backtick. ` is one. You would write `change`.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.