嘿,我有问题...
我想在用户共享我的Facebook应用程序的链接时,我将他的ID放入DB中。
我共享链接的方式是通过我修改的Facebook对话框JavaScript示例
共享JavaScript代码
<script>
FB.init({appId: 'xxxx', channelUrl: 'xxxx', status: true, cookie: true});
function postToFeed() {
// calling the API ...
var obj = {
method: 'feed',
link: 'https://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
name: 'Facebook Dialogs',
caption: 'Reference Documentation',
description: 'Using Dialogs to interact with users.'
};
function callback(response) {
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
document.getElementById('post').style.display = "none";
}
}
xmlhttp.open("POST","shared.php",true);
xmlhttp.send("id=xxx");
}
FB.ui(obj, callback);
}
</script>
PHP代码
$con = mysqli_connect("xxxx","xxx","xxx","xxx");
if (!$con) {
die('Could not connect: ' . mysql_error());
};
mysqli_query($con, "INSERT INTO xxx (fb-id) VALUES (".$_POST['id'].")");
mysqli_close($con)
当我共享链接时,我会得到post_id,但是DB中的任何内容?
有人可以告诉什么问题吗?
无效字段名称:
INSERT INTO xxx (fb-id) ...
^^^^^
看起来像是被减去两个字段,而不是一个字段。您可能想以回头逃脱它,以强迫将其视为一个字段名称:
INSERT INTO xxx (`fb-id`) ...
在Greature图片中,您有一个主要的SQL注入孔。停止处理此代码,并了解如何在某人破坏您的服务器之前避免此问题。
您还假设查询成功,这是一件坏事。您在Connect()调用上都有错误处理,但没有其他地方。永远不要以为查询成功了。之后始终检查错误。