My array print_r is:
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、事件、email、类别、时间戳、响应、尝试、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:xampphtdocseembetaarray_temp.php on line 34
如何插入没有特定顺序的数据?
这与序列无关,但$poke['category']在该数组(要插入的元素)中不存在。确保您想要使用的所有数组字段都已初始化:
$poke['category'] = $poke['category'] ? $poke['category'] : '';
这个代码的意思是:这个字段设置好了吗?是的,使用它。否:使用空字符串。这样$poke['category']是已知的,所以你不会得到错误。
顺便说一句,你可以用0、null或任何你需要的东西来替换"。
在查询中使用数据之前,对其进行清理以避免SQL注入。要实现这一点,可以考虑使用PDO。
回答你的问题
为每个键创建一个临时变量,如下所示:事件=收取美元($ _GET['事件'])? $ _GET['事件']:零;