首页 > 解决方案 > 如何在不获取非法字符串偏移的情况下循环

问题描述

即使记录正确插入,我仍然收到此错误并且无法找到问题所在

INSERT INTO 都出现错误,但是当我检查数据库记录时是否存在并且它是正确的,那么如何处理这个错误?

这是我的代码和转储

$order_id = $this->db->getLastId();
if ($data['options'] != '') {
        foreach ($data['options'] as $filter => $option) {
            $check = $this->db->query("SELECT
                                            oc_product_option.option_id,
                                            oc_option.type,
                                            oc_option_description.name,
                                            oc_product_option_value.option_value_id,
                                            oc_option_value_description.name AS option_name
                                            FROM oc_product_option
                                            LEFT JOIN oc_option ON (oc_product_option.option_id = oc_option.option_id)
                                            LEFT JOIN oc_option_description ON (oc_product_option.option_id = oc_option_description.option_id)
                                            LEFT JOIN oc_product_option_value ON (oc_product_option_value.product_option_value_id = '" . (int)$option . "')
                                            LEFT JOIN oc_option_value_description ON (oc_option_value_description.option_value_id = oc_product_option_value.option_value_id)
                                            WHERE oc_product_option.product_option_id = '" . (int)$filter . "'
                                            AND oc_product_option.product_id = '" . (int)$data['product_id'] . "'");
            foreach ($check->rows as $option_type) {

                if ($option_type['type'] == 'custom') {
                    $this->db->query("INSERT INTO " . DB_PREFIX . "fast_order_option SET order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$data['product_id'] . "', product_option_id = '" . (int)$filter . "', name = '" . $this->db->escape($option_type['name']) . "', value = '" . $this->db->escape($option) . "', type = '" . $this->db->escape($option['type']) . "'");
                }else {
                    $this->db->query("INSERT INTO " . DB_PREFIX . "fast_order_option SET order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$data['product_id'] . "', product_option_id = '" . (int)$filter . "', product_option_value_id = '" . $this->db->escape($option) . "', name = '" . $this->db->escape($option_type['name']) . "', value = '" . $this->db->escape($option_type['option_name']) . "', type = '" . $this->db->escape($option['type']) . "'");
                }
            }
        }
    }

$data['选项']

Array
(
[1330] => 1853
[1181] => 2
[1182] => 1
[1179] => 1660
)

$支票

stdClass Object
(
[num_rows] => 1
[row] => Array
    (
        [option_id] => 16
        [type] => select
        [name] => Двулицев Размер
        [option_value_id] => 56
        [option_name] => 300/100
    )

[rows] => Array
    (
        [0] => Array
            (
                [option_id] => 16
                [type] => select
                [name] => Двулицев Размер
                [option_value_id] => 56
                [option_name] => 300/100
            )

    )

)

标签: php

解决方案


    type = '" . $this->db->escape($option['type']) . "'");
}

$option['type']最后应该有$option_type['type']-$option来自您的外部 foreach 循环,并包含$data['options']此时的整数之一。


推荐阅读