php,mysql脚本。 *应该*按我的意思工作,但不要

时间:2015-06-12 16:25:21

标签: php mysql

所以,我得到了这个脚本:http://pastebin.com/HHnUWnyB 事情是,它不起作用,我不知道为什么,我一遍又一遍地看着它,对我来说它应该工作,但不是。所以现在我转向专家!

而不是在mysql数据库中更新它只返回一个空页...

提前致谢!

更新:发现确切但无法正常工作:http://pastebin.com/pQrdQUPq

$username = 'test';  // note, isn't this in original script, it's called from a database, but whatever 
if(isset($_POST['generate'])) {
$newkey = 'something';
$query = sprintf('UPDATE `users` SET `key`=%s WHERE `username`="%s"',
mysqli_real_escape_string($db, $newkey),
mysqli_real_escape_string($db, $username));
mysqli_query($db, $query);
};

1 个答案:

答案 0 :(得分:0)

似乎未设置POST['disable']POST['generate']。检查是否正在发布这些变量。还有一堆BAD SYNTAX:还有许多额外的结尾括号和不必要的分号。

也尝试更改此内容:

$query = sprintf('UPDATE `users` SET `key`=%s WHERE `username`="%s"',

到此:

$query = sprintf("UPDATE `users` SET `key`='%s' WHERE `username`='%s'",

所以你应该这样:

$username = 'test';  // note, isn't this in original script, it's called from a database, but whatever
if (isset($_POST['generate'])) {
    $newkey = 'something';
    $query = sprintf("UPDATE `users` SET `key`='%s' WHERE `username`='%s'", mysqli_real_escape_string($db, $newkey), mysqli_real_escape_string($db, $username));
    mysqli_query($db, $query);
}