2014-04-19 94 views
1

目前我有WooCommerce,這些是這些代碼將這些信息添加到數據庫我使用wordpress和由於某種原因它提交但沒有將它們添加到數據庫,有些事情是錯誤的,它不工作,但不知道爲什麼?任何人都可以指導什麼問題?數據庫和WooCommerce註冊?

$billing_first_name = $wpdb->escape(trim($_POST['billing_first_name'])); 
    $billing_last_name = $wpdb->escape(trim($_POST['billing_last_name'])); 
    $billing_company = $wpdb->escape(trim($_POST['billing_company'])); 
    $billing_address_1 = $wpdb->escape(trim($_POST['billing_address_1'])); 
    $billing_address_2 = $wpdb->escape(trim($_POST['billing_address_2'])); 
    $billing_city = $wpdb->escape(trim($_POST['billing_city'])); 
    $billing_postcode = $wpdb->escape(trim($_POST['billing_postcode'])); 
    $billing_state = $wpdb->escape(trim($_POST['billing_state'])); 
    $billing_country = $wpdb->escape(trim($_POST['billing_country'])); 
    $billing_phone = $wpdb->escape(trim($_POST['billing_phone'])); 
    $billing_email = $wpdb->escape(trim($_POST['billing_email'])); 
    $shipping_first_name = $wpdb->escape(trim($_POST['shipping_first_name'])); 
    $shipping_last_name = $wpdb->escape(trim($_POST['shipping_last_name'])); 
    $shipping_company = $wpdb->escape(trim($_POST['shipping_company'])); 
    $shipping_address_1 = $wpdb->escape(trim($_POST['shipping_address_1'])); 
    $shipping_address_2 = $wpdb->escape(trim($_POST['shipping_address_2'])); 
    $shipping_city = $wpdb->escape(trim($_POST['shipping_city'])); 
    $shipping_postcode = $wpdb->escape(trim($_POST['shipping_postcode'])); 
    $shipping_state = $wpdb->escape(trim($_POST['shipping_state'])); 
    $shipping_country = $wpdb->escape(trim($_POST['shipping_country'])); 

回答

0

這是因爲你只是分配變量而不是實際進行任何SQL調用。我不知道你想存儲的正是這種信息到底是什麼表,但似乎丟失的是這樣的:

$wpdb->query($wpdb->prepare('insert into destination_table (col1, col2, etc...) values (%s, %s, etc...)', 'val1', 'val2', etc...)); 

我還沒有WooCommerce工作或看到它是如何將其存儲信息,但實際上將數據插入到數據庫中似乎是代碼中缺少的內容。希望這可以幫助!

+0

哦,親愛的,不是線索我有更多的代碼在這裏... http://stackoverflow.com/questions/23176505/data-storing-in-the-database-wordpress-woocommerce有一看我不知道什麼我丟了 :/ – user3348182