在你假设我没有建立数据库连接之前,我做到了。代码中唯一没有更新的是if语句。
所有值都可以正确回显,只是查询不起作用。
这是在目录配置中,名为stuff.php
$user = $mysqli->real_escape_string($_SESSION['username']);
$user_query = "SELECT * FROM users WHERE username = '$user'";
$result = $mysqli->query($user_query);
$row = $result->fetch_assoc();
$referrer = $row['ref'];
$refearn = $row['refearn'];
verify.php
include('config/stuff.php');
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { // Get Real IP
$IP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$IP = $_SERVER['REMOTE_ADDR'];
}
if ($IP=="external server ip here") {
if (!empty($referrer)){
$mysqli->query("UPDATE users SET points=points+10, refearn = refearn+10 WHERE username='".$referrer."'") or die(mysqli_error($mysqli));
}
$mysqli->query("UPDATE users SET points=points+".$earnings.", completed = completed+1 WHERE username='".$subid."'") or die(mysqli_error($mysqli));
}
答案 0 :(得分:1)
我的猜测是你可以尝试通过查询检索点的值然后添加到它,这样你只需要更新为一个简单的值。但是,如果mysql_error()返回错误,那么应该更容易理解。
示例:
$getPoints = mysql_query("SELECT points FROM table WHERE condition");
$points = mysql_result($getPoints, 0, "points");
$update = mysql_query("UPDATE table SET points=" . ($points+10) . " WHERE condition");
希望有所帮助。但另一个考虑因素。为什么要使用endif结构,除非你打破PHP标签来显示内容?
答案 1 :(得分:0)
试试这个:
$mysqli->query("UPDATE `users` SET `points`=`points`+10, `refearn` = `refearn`+10 WHERE `username`='".$referrer."'") or die(mysqli_error($mysqli));
希望这会有所帮助。我认为,mysql查询可能会将这些视为常量 - 而不是mysql行。试试那个