我是关于php和mysql的新手,我的脚本有问题。
我喜欢在数据库的特定行中保存/更新_GET值(其中facebook的ID是我数据库中的id)
php中的脚本:
<?php
header('Access-Control-Allow-Origin: *');
//////////////////////////////FACEBOOK LOAD
require 'client/facebook.php';
$app_id = "***";
$secret = "***";
$app_url = "***";
// Create our Application instance
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $secret,
));
// Get User ID
$user = $facebook->getUser();
//Do we have a user?
if(!$user) {
$loginUrl = $facebook->getLoginUrl(array('redirect_uri'=> $app_url));
//redirect the url to prompt for login and permissions
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
} else {
try{
//Proced knowing you have a logged in user who's autenticated
$user_profile = $facebook->api('/me');
$name = $user_profile['name'];
$id = $user_profile['id'];
$first_name = $user_profile['first_name'];
$last_name = $user_profile['last_name'];
$link = $user_profile['link'];
$username = $user_profile['username'];
$gender = $user_profile['gender'];
$locale = $user_profile['locale'];
} catch (FacebookApiException $e) {
echo ($e);
$user = null;
}
}
// Get User ID
//////////////// CONNECT DATABASE
$sdb = "MYHOST";
$db = "gioco";
$userdb = "root";
$passdb = "";
$dblink = mysql_connect($sdb,$userdb,$passdb);
$seldb = mysql_select_db($db);
//$user_type ="aa"; //USER DATA
$connection =""; //variable for start function check UID
$checkUIDdb ="INATTESA"; //check if exist the UID facebook
$insertnewuser ="";
$loadspecific ="inattesa";
$idC2= $_GET["idC2"];
$gold= $_GET["goldurl"];
///
///CHECK CONNECTION WITH DATABASE
///
$mysqlConnection = mysql_connect($sdb, $userdb, $passdb);
if (!$mysqlConnection)
{
echo "NO DATABASE FOUND, CHECK USER, PASS, DB";
}
else
{
$connection = "ok";
mysql_select_db($db, $mysqlConnection);
}
////////////////////PROBLEM******************************
if ( $id == $idC2 ) { ////IF ID FROM FACEBOOK API IS = ID FACEBOOK FROM GAME
//$gold = strip_tags(mysql_real_escape_string($gold));
//$sql = mysql_query("UPDATE gioco tabletest goldDB='$gold' WHERE UIDfacebook='$id'");
$sql = "UPDATE goldDB = $gold FROM tabletest WHERE UIDfacebook = $id";
if($sql){
//The query returned true - now do whatever you like here.
echo $connection = "SAVEDATA";
}else{
//The query returned false - you might want to put some sort of error reporting here. Even logging the error to a text file is fine.
echo $connection = "ERROR, NO SAVEDATA";
}
}else{
//echo "\\";
}
?>
但我不知道怎么写:
SAVE/UPDATE ON "namedatabase" "nametable" "name colunm,in this case goldDB" WHERE UIDFACEBOOK = $id"