私はこれに約2日間取り組んできましたが、コードとエラーログを何時間もチェックした後、解決策を見つけることができません。だから、私はいくつかの新鮮な目が役立つことを願っています。
Facebookのデータを収集してデータベースに挿入しています。$ sql INSERTコマンドでvar_dumpを実行すると、文字列内のすべてのFacebookデータが表示されます。また、各変数に対してvar_dumpsを実行して、データがそこにあることを確認しました。それは、それぞれが文字列型として表示されます。これは、データベースが期待しているものと一致します。十分なスペースがあるVARCHARです。
このデータベースには他にもいくつかのテーブルがありますが、それらはまだデータを受け入れているため、データベースの問題ではないようです(これは共有サーバーであり、アクセスできません)。また、INSERTステートメントで構文のほとんどすべてのバリエーション、異なる引用符などのように見えるものを試しましたが、役に立ちませんでした...。
最後に、mysql_error()の結果として得られるエラーは、「SQL構文にエラーがあります。MySQLサーバーのバージョンに対応するマニュアルで、'mの近くで使用する正しい構文を確認してください。 fun ....'、' AAAIAZB21He9sBAOLpbm3XTwabMVX0s'at line1"。一重引用符(')で表示されているのは、INSERTステートメントの$fbaboutおよび$atVALUESの現在のデータです。
これで、phpファイルのコードは次のようになります。よろしくお願いします!
<?php
require_once("facebook.php");
$app_id = "";
$app_secret = "";
$my_url = "";
$code = $_POST["code"];
if(empty($code)) {
$dialog_url = "https://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="
. $_SESSION['state']."&scope=email,user_birthday,user_interests,friends_interests,publish_stream,user_about_me,user_checkins";
echo("<script> top.location.href='" . $dialog_url . "'</script>");
} else {
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$token_url = "https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret . "&code=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$_SESSION['access_token'] = $params['access_token'];
$graph_url = "https://graph.facebook.com/me?access_token=". $params['access_token'];
$interests = "https://graph.facebook.com/me/interests?access_token=". $params['access_token'];
$user = json_decode(file_get_contents($graph_url));
$user_interests = json_decode(file_get_contents($interests));
$id = $user->id;
$fname = $user->first_name;
$lname = $user->last_name;
$link = $user->link;
$gender = $user->gender;
$locale = $user->location->name;
$email = $user->email;
$bday = $user->birthday;
$uidata = array();
$number = count($user_interests->data);
for ($i = 0;$i<=$number-1;$i++){
array_push($uidata,($user_interests->data[$i]->name));
}
$ui = implode(",", $uidata);
$fbabout = $user->bio;
$at = $params['access_token'];
// Insert data into mysql
$sql="INSERT INTO $tbl_name(fbid,fname,lname,link,gender,locale,email,birthday,interests,fbabout,fbtoken)VALUES('".$id."','".$fname."','".$lname."','".$link."','".$gender."','".$locale."','".$email."','".$bday."','".$ui."','".$fbabout."','".$at."')";
$result=mysql_query($sql);
if($result) {
header( 'Location: https://crushonit.com/join/fbRegister.html' );
} else {
echo mysql_error();
}
}
?>
<?php
// close connection
mysql_close();
?>