0

我的数组 print_r 是:

Array
(
    [email] => xxx@cs.caddmu.edu
    [attempt] => 0
    [timestamp] => 1369676665
    [smtp-id] => <1369676650.51a39b6a76cec@www.openaccesspub.org>
    [response] => 451 4.2.0 Temporarily Grey listed.  Try again in a couple of minutes 
    [category] => Invitation
    [event] => deferred
)
Array
(
    [email] => reidsdds@cs.cdsmu.edu
    [timestamp] => 1369676845
    [smtp-id] => <1369676650.51a39b6a76cec@www.openaccesspub.org>
    [response] => 250 2.0.0 r4RHlOGH017661 Message accepted for delivery 
    [category] => Invitation
    [event] => delivered
)
Array
(
    [email] => jrai@openhh.com
    [timestamp] => 1369678994
    [smtp-id] => <1369678990.51a3a48e93428@ohhpb.org>
    [category] => Reviewers
    [event] => processed
)
Array
(
    [email] => sss@lusst.fi
    [timestamp] => 1369678997
    [smtp-id] => <1369678990.51a3a48e93428@oub.org>
    [response] => 250 2.0.0 Ok: queued as 02C103F0454 
    [category] => Revie
    [event] => delivered
)

表格有这些行:

event_id、事件、电子邮件、类别、时间戳、响应、尝试、url、状态、原因、类型、操作、m_id。

我正在尝试使用以下内容插入 mysql 表:-

foreach ($temp_array as $key => $poke) 
{ 
    mysql_query ("INSERT INTO temp_array (email,timestamp,category,event,response,attempt,reason,o_id,operator,action,...)VALUES ('$poke[email]','$poke[timestamp]','$poke[category]','$poke[event]',.... )" ); 
}

但我收到错误“未定义索引:类别在

  C:\xampp\htdocs\eembeta\array_temp.php on line 34

如何插入没有特定顺序的数据?

4

2 回答 2

0

这与序列无关,但该数组(要插入的元素)中不存在 $poke['category'] 。确保您要使用的所有数组字段都已初始化:

$poke['category'] = $poke['category'] ? $poke['category'] : '';

该代码的意思是:该字段是否已设置?是的:使用它。否:使用空字符串。这样 $poke['category'] 是已知的,所以你不会出错。

顺便说一句,您可以将 '' 替换为 0、null 或您需要的任何内容。

于 2013-06-04T20:31:38.493 回答
0

在使用查询中的数据之前,先对其进行清理以避免 SQL 注入。为此,请考虑使用 PDO。

回答你的问题

对于每个键,创建一个临时变量,例如: $event = isset($_GET ['event']) ?$_GET ['event'] : null;

于 2013-06-04T20:33:04.857 回答