0

我在使用 wordpress query() 函数时遇到了非常奇怪的问题。

我在第 1 页上有一个表格,下面的代码插入一条新记录。

if(isset($_POST["transaction_id"])){
    global $wpdb;
    $sql = $wpdb->prepare( " INSERT INTO `{$wpdb->prefix}v_cards` (transaction_id, user_id) VALUES ( %d, %d)", $_POST['transaction_id'], $_POST['user_id']);
    $wpdb->query($sql);
    $_SESSION['card_id'] = $wpdb->insert_id;
}


And on submit below Update query fires to update a row
    $sql = $wpdb->prepare('UPDATE '.$wpdb->prefix.'v_cards SET
                                        prefix=%s,
                                        first_name=%s,
                                        middle_name=%s,
                                        last_name=%s,
                                        suffix=%s,
                                        degree=%s,
                                        description=%s,
                                        copyright=%s,
                                        background=%s,
                                        photo=%s,
                                        call_country_code=%s,
                                        call_number=%s,
                                        call_ext=%s,
                                        call_activate=%s,
                                        text_country_code=%s,
                                        text_number=%s,
                                        text_ext=%s,
                                        text_activate=%s,
                                        email=%s,
                                        email_activate=%s,
                                        find_location_name=%s,
                                        find_address_1=%s,
                                        find_address_2=%s,
                                    find_city=%s,
                                    find_state=%s,
                                    find_postcode=%s,
                                    find_country_code=%s,
                                    find_activate=%s,
                                    profile_details=%s,
                                    profile_activate=%s,
                                    organization=%s,
                                    org_industry=%s,
                                    org_country=%s,
                                    org_address_1=%s,
                                    org_address_2=%s,
                                    org_city=%s,
                                    org_state=%s,
                                    org_postcode=%s,
                                    org_phone=%s,
                                    org_fax=%s,
                                    org_email=%s,
                                        org_details=%s,
                                        org_activate=%s,
                                        contact_location_name=%s,
                                        contact_country=%s,
                                        contact_address_1=%s,
                                        contact_address_2=%s,
                                        contact_city=%s,
                                        contact_state=%s,
                                        contact_postcode=%s,
                                        contact_phone=%s,
                                        contact_fax=%s,
                                        contact_email=%s,
                                        contact_activate=%s,
                                        my_sites_title=%s,
                                        my_sites_url=%s,
                                        my_sites_activate=%s,
                                        social_title=%s,
                                        social_url=%s,
                                        social_activate=%s,
                                        icon=%s,
                                        card_name=%s,
                                        card_status=%s,
                                        modify_date=SYSDATE()
                                    WHERE id = %s', $_POST['prefix'], $_POST['first_name'], $_POST['middle_name'], $_POST['last_name'], $_POST['suffix'], $_POST['degree'], $_POST['description'], $_POST['copyright'], $background_id, $icon_id, $_POST['call_country_code'], $_POST['call_number'], $_POST['call_ext'], $_POST['call_activate'], $_POST['text_country_code'], $_POST['text_number'], $_POST['text_ext'], $_POST['text_activate'], $_POST['email'], $_POST['email_activate'], $_POST['find_location_name'], $_POST['find_address_1'], $_POST['find_address_2'], $_POST['find_city'], $_POST['find_state'], $_POST['find_postcode'], $_POST['find_country_code'], $_POST['find_activate'], $_POST['profile_details'], $_POST['profile_activate'], $_POST['organization'], $_POST['org_industry'], $_POST['org_country'], $_POST['org_address_1'], $_POST['org_address_2'], $_POST['org_city'], $_POST['org_state'], $_POST['org_postcode'], $_POST['org_phone'], $_POST['org_fax'], $_POST['org_email'], $_POST['org_details'], $_POST['org_activate'], $_POST['contact_location_name'], $_POST['country_contact'], $_POST['contact_address_1'], $_POST['contact_address_2'], $_POST['contact_city'], $_POST['contact_state'], $_POST['contact_postcode'], $_POST['contact_phone'], $_POST['contact_fax'], $_POST['contact_email'], $_POST['contact_activate'], $_POST['my_sites_title'], $_POST['my_sites_url'], $_POST['my_sites_activate'], $_POST['social_title'], $_POST['social_url'], $_POST['social_activate'], $icon_id, $_POST['card_name'], $_POST['card_status'], $_SESSION['card_id']);

    $wpdb->query($sql);

但是当我提交表单时,它会插入一个新行并更新一个旧行所有代码都写在一个 Wordpress 小部件(第二个顶部小部件区域)中。

提前致谢

4

1 回答 1

0

如果 xdebug 已激活,请尝试禁用它。当 xdebug 处于活动状态时,我也发生了同样的错误。

于 2015-11-20T12:24:13.490 回答