这是 .xml 格式:
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><!--File Created By Call Logs Backup & Restore v3.21 on 29/08/2013 19:53:23--><?xml-stylesheet type="xsl" href="calls.xsl"?>
<calls count="500">
<call number="+919257035805" duration="0" date="1377691732581" type="3" readable_date="28/08/2013 17:38:52" contact_name="(Unknown)" />
<call number="+919257035805" duration="38" date="1377691747866" type="2" readable_date="28/08/2013 17:39:07" contact_name="(Unknown)" />
</calls>
这是 .php 脚本
if ($_FILES[xml][size] > 0) {
$file = $_FILES[xml][tmp_name];
$xml = simplexml_load_file($file);
$count = 0;
foreach ($xml->call as $call) {
$number = mysql_real_escape_string($call->number);
$duration = mysql_real_escape_string($call->duration);
$type = mysql_real_escape_string($call->type);
$readable_date = mysql_real_escape_string($call->readable_date);
$contact_name = mysql_real_escape_string($call->contact_name);
mysql_query("INSERT INTO call_log (number, duration, type, readable_date, contact_name ) VALUES ('$number', '$duration', '$type', '$readable_date', '$contact_name')") or die ("Error in query: $insert. ".mysql_error());
}
//redirect
header('Location: upload_sql.php?success=1?inserts=' . $count . ''); die;
}
但是这个脚本不会向表中添加任何值......完全空白