2011-02-25 124 views
0

我有一個惡夢試圖插入一些數據到表中。出於某種原因,它只會讓我插入數字,而不是將文本插入到特定的行中,甚至不會插入任何單詞。我已經嘗試將行設置爲不同的類型(文本,Varchar,Longtext),但沒有任何理由可以讓人高興?我之前完成了這些工作,我完全陷入了爲什麼現在不工作。mysql插入文本問題

問題行是order_note和測試,這裏的查詢:

$table_name = $wpdb->prefix . "dpsc_transactions"; 
$query = "INSERT INTO {$table_name} (`invoice`, `date`, `order_time`, `billing_first_name`, `billing_last_name`, `billing_country`, 
`billing_address`, `billing_city`, `billing_state`, `billing_zipcode`, `billing_email`, `phone`, `shipping_first_name`, `shipping_last_name`, 
`shipping_country`, `shipping_address`, `shipping_city`, `shipping_state`, `shipping_zipcode`, `products`, `payment_option`, `discount`, 
`tax`, `shipping`, `total`, `order_note`, `test`, `payment_status`) VALUES ('{$invoice}', NOW(), {$order_time}, '{$bfname}', '{$blname}', '{$bcountry}', '{$baddress}', 
'{$bcity}', '{$bstate}', '{$bzip}', '{$bemail}', '{$phone}', '{$sfname}', '{$slname}', '{$scountry}', '{$saddress}', '{$scity}', '{$sstate}', '{$szip}', 
'{$products}', '{$payment_option}', {$dpsc_discount_value}, {$tax}, {$dpsc_shipping_value}, {$dpsc_total}, {$order_note}, {$test}, 'Pending')"; 
$wpdb->query($query); 
+2

什麼是mysql錯誤,你看到了嗎? – Ish 2011-02-25 18:32:13

+0

'row_id = woodoo'?粘貼錯誤。 – Nishant 2011-02-25 18:37:29

回答

0

試試這個:

$query = "INSERT INTO {$wpdb->prefix}dpsc_transactions (`invoice`, `date`, `order_time`, `billing_first_name`, `billing_last_name`, `billing_country`, 
`billing_address`, `billing_city`, `billing_state`, `billing_zipcode`, `billing_email`, `phone`, `shipping_first_name`, `shipping_last_name`, 
`shipping_country`, `shipping_address`, `shipping_city`, `shipping_state`, `shipping_zipcode`, `products`, `payment_option`, `discount`, 
`tax`, `shipping`, `total`, `order_note`, `test`, `payment_status`) VALUES ('{$invoice}', NOW(), '{$order_time}', '{$bfname}', '{$blname}', '{$bcountry}', '{$baddress}', 
'{$bcity}', '{$bstate}', '{$bzip}', '{$bemail}', '{$phone}', '{$sfname}', '{$slname}', '{$scountry}', '{$saddress}', '{$scity}', '{$sstate}', '{$szip}', 
'{$products}', '{$payment_option}', '{$dpsc_discount_value}', '{$tax}', '{$dpsc_shipping_value}', '{$dpsc_total}', '{$order_note}', '{$test}', 'Pending')"; 
$wpdb->query($query); 

或者告訴說什麼MySQL錯誤。

+1

解釋你改變了什麼通常是一個好主意:)當然,我發現它,但它花了一分鐘。 – corsiKa 2011-02-25 18:40:18

+1

更改是在VALUES()部分的'test'和'order_note'變量周圍加上引號。 – 2011-02-25 20:09:25

+1

**是的,我需要在變量**周圍添加引號,如果您插入的數字不需要引號,並且您要插入文本,則必須這樣做。當我從數字變量複製代碼時,我錯過了引號!最簡單的事情浪費了大量的時間。 **非常感謝您的幫助。** – 2011-02-26 14:26:38

0

你不嘗試插入數據時間太長是你嗎?

+0

OP說,「甚至沒有一個單詞」 – Nishant 2011-02-25 18:38:17