0

Все привет!

Получаю ошибку:

Error Number: 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 'WHERE id = '5'' at line 15 UPDATE transactions SET type = '4', sum = '1000.00', fee = '50.00', amount = '1200.00', status = '4', sender = 'admin', receiver = 'testuser1', user_comment = '', admin_comment = '', check_notify = '1', notification = '', WHERE id = '5'

Код запроса:

function edit_transaction($data = array())
{
    if ($data)
    {
        $sql = "
            UPDATE {$this->_db}
            SET
                type = " . $this->db->escape($data['type']) . ",
                                     sum = " . $this->db->escape($data['sum']) . ",
                fee = " . $this->db->escape($data['fee']) . ",
                amount = " . $this->db->escape($data['amount']) . ",
                status = " . $this->db->escape($data['status']) . ",
                sender = " . $this->db->escape($data['sender']) . ",
                receiver = " . $this->db->escape($data['receiver']) . ",
                user_comment = " . $this->db->escape($data['user_comment']) . ",
                admin_comment = " . $this->db->escape($data['admin_comment']) . ",
                check_notify = " . $this->db->escape($data['check_notify']) . ",
                notification = " . $this->db->escape($data['notification']) . ",
            WHERE id = " . $this->db->escape($data['id']) . "
        ";

        $this->db->query($sql);

        if ($this->db->affected_rows())
        {
            return TRUE;
        }
    }

    return FALSE;
}

Вопрос:

Почему я получаю ошибку? Проект на CI.

Благодарен за любую помощь.

1 ответ 1

2

Возможно данная проблема исходит из синтаксической ошибки, заметил одну

 notification = " . $this->db->escape($data['notification']) . ",
            WHERE id = " . $this->db->escape($data['id']) . "

лишний знак запятой до WHERE, должно быть так

 notification = " . $this->db->escape($data['notification']) . "
            WHERE id = " . $this->db->escape($data['id']) . "

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.