mysql数组插入重复字段数组

时间:2017-03-20 18:14:15

标签: php mysql arrays

我有这个PHP代码插入到mysql中。

require_once("../form/corefile/functions.php");
$fn = new Functions();
$offers = $_REQUEST;
$offer=$_REQUEST['offer'];
$website =$_REQUEST['website'];
$keyword =$_REQUEST['keyword'];


$count_offer = count($_REQUEST['offer']);
var_dump($offer);exit;

for($i=0;$i<$count_offer ;$i++){
    $_offer  = ($offer[$i]);       
    $_website  = ($website[$i]);
    $_keyword  = ($offer[$i]);

    $query = $fn->InsertQuery("INSERT INTO offers (offer, website, keyword) VALUES ('$_offer','$_website','$_keyword')");
    //var_dump($query);exit;
    if($query)
{
$msg="Data Successfully Saved";
}

}

var_dump($offer)的数组看起来像这样;

array (size=2)
  0 => 
    array (size=1)
      'name' => string 'offer1' (length=6)
  1 => 
    array (size=1)
      'name' => string 'offer2' (length=6)

我收到错误: Notice: Array to string conversion in repeat.php on line 19 第19行是$query = $fn->insertQuery

看起来我从数组中提取正确的数据时犯了一些错误。

1 个答案:

答案 0 :(得分:0)

数组$ offer是一个关联数组数组。$ offer [0]将返回一个奇异键值对的数组,其中ofcourse不是String,因此是错误。