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的插件的所有代码(第二顶部件区)。
在此先感谢
我对你有这段代码的地方有点困惑吗?它在我看来,“提交”(isset($ _ POST [“transaction_id”])){“和”$ sql = $ wpdb-> prepare('UPDATE'。$ wpdb-> prefix。“)在SUBMIT上。我错了? – user850010 2013-05-14 20:26:37
是的,两者都在SUBMIT上,但在不同的小部件上。 – user1531437 2013-05-16 04:59:36
我没有太多的小部件开发经验,所以我无法帮助你。你可以在http://wordpress.stackexchange中试试你的问题。 COM / – user850010 2013-05-16 08:16:45