我试图从JSON格式的网站获取信息,然后将其导入到指定的表中。到目前为止,我已经设法将JSON解密为可管理的格式。从那里开始,我试图将这些数据插入到数组中,然后根据需要将其导入到指定的表中。我真的迷失了。我用于构建这个脚本的所有信息都在Stackoverflow上找到,我非常感谢您的帮助。File_get_contents,PHP,MySQL插入问题
**USER.PHP**
<?php
$user = file_get_contents('https://graph.facebook.com/sean.wichers');
$json = json_decode($user, true);
{
$uinfo = array(
'id' => $json->$id,
'name' => $json->$name,
'first_name' => $json->$first_name,
'last_name' => $json->$last_name,
'link' => $json->$link,
'username' => $json->$username,
'gender' => $json->$gender,
'locale' => $json->$locale
);
}
include 'user1.php';
?>
USER1.PHP
<?php
$con = mysql_connect("localhost","s*ic*ers_t*g*","******");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("*wi*he*_***", $con);
$sql="INSERT INTO jos_users (id, name, username, usertype, block, sendEmail, gid)
VALUES ('$id', '$name', '$username', 'Registered', 0, 1, 18)"
mysql_close($con);
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
echo "1 record added... BOOM BABY!!!";
?>
你可以简单地使用第一个片段,'$ UINFO =(阵列)$ json' – 2012-03-28 02:30:46
的答复谢谢!但是,在做出更改后,我得到: 解析错误:语法错误,意外的T_CONSTANT_ENCAPSED_STRING在第6行的/home/swichers/tagn.it/adduser/1/user.php中 您可以在http:/ /tagn.it/adduser/1/user.php – user1262407 2012-03-28 02:38:50
您是否添加了分号? '$ uinfo =(array)$ json;' – 2012-03-28 02:44:17