On the ckeckout page, when the firstname or lastname contains a character " ' " then I get an error when placing the order:

exception 'PDOException' with message '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 'Conor','Aug 21, 2019','4','Test O'Conor')' at line 1'

To fix this I override the class Mage_Customer_Model_Customer and method _beforeSave():

protected function _beforeSave()
    $firstName = $this->getFirstname();
    if ( $firstName ) {
        $this->setFirstname( addslashes($firstName) );
    $lastName = $this->getLastname();
    if ( $lastName ) {
        $this->setLastname( addslashes($lastName) );


However, now in the admin panel I get the wrong usernames:

"T\'Est O\'Conor", "T\'Est O\'Conor", etc...

I tried to override the customer collection Mage_Customer_Model_Resource_Customer_Collection and methods load() and getData(). But in the admin panel left "\" in the names. I thought Magento had to handle these situations on her own, but she didn't. How do I fix this error?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.