0

So I am working with a very old site where the client wont let me upgrade it to any sort of PDO. Anyway I have to use mysql querys and its really starting to depress me. I cant seem to get this to work:

$array = array('1' => 1, '2' => 2);

$values = "({$array['1']}, 2, 'data3', 4, 5)";

if ($moreData){
    $values = $values.", ({$array['6']}, 7, 'data8', 9, 10)";
}

$this->db->query("INSERT INTO " . DB_PREFIX . "customer_reward ".
                 "('field1','field2','field3','field4','field5') ".
                 "VALUES ".$values);

Any help would be greatly appreciated.

UPDATE:

Here Is The Error Message:

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 ''field1','field2','field3','field4','field5') VALUES (1, 2, 'data3' at line 1<br />Error No: 1064<br />INSERT INTO table ('field1','field2','field3','field4','field5') VALUES (1, 2, 'data3', 4, 5)
2
  • 3
    Echo out the SQL you're generating and run it in the database, and see what the error message is. Commented Oct 1, 2012 at 19:43
  • @JasonMcCreary He hasn't got PDO. Commented Oct 1, 2012 at 19:46

1 Answer 1

2

The field names in your query should not be within single quotes. They either need to have no quotes or be inside back-ticks.

You also need to make sure the field types match the data types as you are trying to enter in some integer values.

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

Comments

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.