将php数组写入mysql,将php数组插入mysql表

Update:

I forgot to mention that echo $matstring outputs '65.70', 'Coles','34 days','14' - which would appear to be the right syntax?

I'm a php/mysql newbie, and I think this is fairly basic, but having read all of the other stackoverflow questions on this topic and fiddling with different versions of my code for several hours I can't understand what I'm doing wrong. Would very much appreciate any help/suggestions.

Aim: pass data from my php array ($matrix) into a mysql table

$matrix[1]=

( [0] => 65.70 [1] => Coles [2] => 34 days [3] => 14 )

$matrix[2]=

( [0] => 62.70 [1] => Coles [2] => 13 days [3] => 14 )

$matrix[3]=

( [0] => 12.70 [1] => Safeway [2] => 43 days [3] => 14 )

Code:

$matstring=implode("','",$matrix[1]);

$matstring="'".$matstring."'";

mysql_query('INSERT INTO Australia (Price, Company, Days, Weight) VALUES ('$matstring')');

解决方案

Corrected code:

$matstring=implode("','",$matrix[1]);

mysql_query("INSERT INTO Australia (Price, Company, Days, Weight) VALUES ('$matstring')");

(i.e. delete the second line from original code and put double quotes around the argument of mysql_query)

Appreciate user1847757's help - as s/he pointed out, $matstring itself was correct, but the single quotes inside of VALUES(' ') were being joined to the single quotes added to $matstring in the 2nd line of my original code, resulting in VALUES(''65.70','Coles','34 days','14'')

Thanks all for your help & suggestions

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值