0

Before you assume I didn't establish a database connection, I did. the only portion of the code that does not update is the if empty statements.

All the values can be echoed out correctly, it's just that query doesn't work.

This is in directory config and named 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));
}       
6
  • do you get any error? or, could you try getting output of that query "UPDATE users SET points=points+10, refearn = refearn+10 WHERE username='".$referrer."'" and check that in phpmyadmin manually - if that work.. Commented Nov 12, 2012 at 5:17
  • There's no error from what I can tell. I can confirm it works in PHPmyadmin, I'm working on echoing it out right now. I'm having a brainfart right now, how can I echo out the query? Commented Nov 12, 2012 at 5:18
  • So it is updating your just trying to output the response? Commented Nov 12, 2012 at 5:25
  • If I manually type it out into PHPmyadmin, with the corresponding $referrer value, it works. Commented Nov 12, 2012 at 5:33
  • Did you check my answer? Is it still not working? Commented Nov 12, 2012 at 5:40

2 Answers 2

1

My guess is you could try to retrieve the value of points through a query then add to it so you're just updating to a simple value. However, if mysql_error() is returning an error, it should be easier to figure out.

Example:

$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");

Hope that helps. Another consideration, though. Why use an endif structure unless you're breaking PHP tags to display content?

Sign up to request clarification or add additional context in comments.

1 Comment

I don't think it will make a different though... My syntax is already correct so I don't understand why it won't work.
0

try this:

$mysqli->query("UPDATE `users` SET `points`=`points`+10, `refearn` = `refearn`+10 WHERE `username`='".$referrer."'") or die(mysqli_error($mysqli)); 

Hope this helps. What I think is, mysql query might be taking those as constant - not as the mysql rows. Try that

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.