2011-02-25 127 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