0

I am using this code to insert into a database, however for some reason it is giving me an error now. Is there a something that needs to be done when it is numbers?

SQLSTATE[42000]: Syntax error or access violation: 1064 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 'replace, pick) VALUES ('8', '1', '6', '1')' at line 1

$sql = "INSERT INTO TRIPLECROWNscratch (user_id, original, replace, pick) VALUES (:user_id, :original, :replace, :pick)";
        $stmt = $dbh->prepare($sql);
        $stmt->bindValue(':user_id', $_POST['user_id'], PDO::PARAM_INT);
        $stmt->bindValue(':original', $_POST['original'], PDO::PARAM_INT);
        $stmt->bindValue(':replace', $replace, PDO::PARAM_INT);
        $stmt->bindValue(':pick', $_POST['pick'], PDO::PARAM_INT);
        $stmt->execute();

1 Answer 1

3

replace is a reserved word and needs to be escaped with backticks.

INSERT INTO TRIPLECROWNscratch (user_id, original, `replace`, pick) VALUES ...
Sign up to request clarification or add additional context in comments.

1 Comment

dang those reserved words haha

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.