ffxpwns Posted May 22, 2012 Share Posted May 22, 2012 Okay, I have posted before, but I truly cannot get this working. I wans a script where upon entering a page, if someone referred that person, they are awarded 5$. I thought I had it down, but it will not set the column 'refer' to null after the page laods, as it should. And it will not award the referrer with the money if the referrer has any information in their 'refer' column. Please let me know if that made sense or not, and I will try and clarify. Here is the code I'm trying to add: $query = "UPDATE ".$DBPrefix."users SET balance = balance + 5 WHERE refer = '".mysql_real_escape_string($referName)."'"; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); $gateway_data = mysql_fetch_assoc($res); $referName = $gateway_data['refer']; $query = "UPDATE ".$DBPrefix."users SET refer = '' WHERE nick = '".mysql_real_escape_string($referred)."'"; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); $gateway_data = mysql_fetch_assoc($res); $referred = $gateway_data['nick']; And heres the code I'm trying to add that ^ to. http://pastebin.com/rwcN7FeJ I tried adding it at around line 12. Theres one more thing, if I do this (code below) it does it correctly, but it clears all the 'refer' data for everyone, not just the one user. $query = "UPDATE ".$DBPrefix."users SET balance = balance + 5 WHERE refer = '".mysql_real_escape_string($referName)."'"; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); $gateway_data = mysql_fetch_assoc($res); $referName = $gateway_data['refer']; $query = "UPDATE ".$DBPrefix."users SET refer = ' ' "; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); Essentially, I want to do this: 'nick' 'refer' 'balance' --------+---------+---------+ | a | b | 0.00 | --------+----------+--------+ |b | c | 0 .00 | --------+----------+--------| |c | a | 0.00 | ------------------------------ Then user 'a' buys something, thus 'b' gets the bonus for referring them, and 'a' gets their refer set to a null value like: 'nick' 'refer' 'balance' --------+---------+---------+ | a | NULL | 0.00 | --------+----------+--------+ |b | c | 5 .00 | --------+----------+--------| |c | a | 0.00 | ------------------------------ Quote Link to comment Share on other sites More sharing options...
ffxpwns Posted May 22, 2012 Author Share Posted May 22, 2012 I should add that it doesn't have to be that code, but thats what I wrote. If you think I need to change it, let me know. Quote Link to comment Share on other sites More sharing options...
Jamdog Posted May 23, 2012 Share Posted May 23, 2012 In your first bit of code: $query = "UPDATE ".$DBPrefix."users SET balance = balance + 5 WHERE refer = '".mysql_real_escape_string($referName)."'"; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); $gateway_data = mysql_fetch_assoc($res); $referName = $gateway_data['refer']; $query = "UPDATE ".$DBPrefix."users SET refer = '' WHERE nick = '".mysql_real_escape_string($referred)."'"; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); $gateway_data = mysql_fetch_assoc($res); $referred = $gateway_data['nick']; You seem to be setting the $query with variables that you create afterwards. So, in the first query: $query = "UPDATE ".$DBPrefix."users SET balance = balance + 5 WHERE refer = '".mysql_real_escape_string($referName)."'"; $referName doesn't exist, so if you were to echo $query; , it would show: UPDATE mydb.users SET balance = balance + 5 WHERE refer = '' What you need to do is to get the referrer from the database first, I'd do this by adding a function: function getReferName($n) { $query = "SELECT refer FROM ".$DBPrefix."users WHERE nick = '".mysql_real_escape_string($n)."'"; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); /* Should only be one result */ $row = mysql_fetch_assoc($res); $referName = $row['refer']; return ($referName); } Now, you can use that in your script like: // Assume we have $userName $referName = getReferName($userName); // Who referred userName? $query = "UPDATE ".$DBPrefix."users SET balance = balance + 5 WHERE refer = '".mysql_real_escape_string($userName)."'"; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); $query = "UPDATE ".$DBPrefix."users SET refer = '' WHERE nick = '".mysql_real_escape_string($referName)."'"; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); Note that I removed the $gateway_data lines from each query - they seemed to be doing nothing useful. Put them back in only if you needed the variables after this point... Quote Link to comment Share on other sites More sharing options...
ffxpwns Posted May 23, 2012 Author Share Posted May 23, 2012 In your first bit of code: $query = "UPDATE ".$DBPrefix."users SET balance = balance + 5 WHERE refer = '".mysql_real_escape_string($referName)."'"; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); $gateway_data = mysql_fetch_assoc($res); $referName = $gateway_data['refer']; $query = "UPDATE ".$DBPrefix."users SET refer = '' WHERE nick = '".mysql_real_escape_string($referred)."'"; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); $gateway_data = mysql_fetch_assoc($res); $referred = $gateway_data['nick']; .... Well, major thing, it doesn't work. It says Fatal error: Call to a member function check_mysql() on a non-object in /.../html/pennybid/pay.php on line 18 And line 18 is shown in the group of text here (just to give context) $query = "SELECT refer FROM ".$DBPrefix."users WHERE nick = '".mysql_real_escape_string($n)."'"; $res = mysql_query($query); /*line 18 below*/ $system->check_mysql($res, $query, __LINE__, __FILE__); /*line 18 above*/ /* Should only be one result */ $row = mysql_fetch_assoc($res); $referName = $row['refer']; But anyways, I am calling $userName like so: $userName = $user->user_data['nick']; And I'll put it in context just to make sure I'm doing it right. function getReferName($n) { $query = "SELECT refer FROM ".$DBPrefix."users WHERE nick = '".mysql_real_escape_string($n)."'"; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); /* Should only be one result */ $row = mysql_fetch_assoc($res); $referName = $row['refer']; return ($referName); } $userName = $user->user_data['nick']; $referName = getReferName($userName); // Who referred userName? $query = "UPDATE ".$DBPrefix."users SET balance = balance + 5 WHERE refer = '".mysql_real_escape_string($userName)."'"; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); $query = "UPDATE ".$DBPrefix."users SET refer = '' WHERE nick = '".mysql_real_escape_string($referName)."'"; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); Quote Link to comment Share on other sites More sharing options...
ffxpwns Posted May 23, 2012 Author Share Posted May 23, 2012 And the call for userName does work, say I'm logged in as ffxpwns, I put in $userName = $user->user_data['nick']; then print_r ($userName); it says ffxpwns. So I assume that's not broken. This may seem super obvious to you, but PHP isn't my strongpoint. Quote Link to comment Share on other sites More sharing options...
ffxpwns Posted May 23, 2012 Author Share Posted May 23, 2012 And, somewhat unsurprisingly, just commenting it out does not work. Quote Link to comment Share on other sites More sharing options...
ffxpwns Posted May 23, 2012 Author Share Posted May 23, 2012 I know it's frowned upon to bump a post, but I am so lost and I need to get this done. Could someone please help me figure out why I'm getting that error? This is how I feel. Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 23, 2012 Share Posted May 23, 2012 That is an awesome picture. $system is not defined within the context of that function. You said when you comment out line 18 you still get the error? I can only assume it changes to a different line number? Because you have $system->check_mysql in 3 places there, but $system is never defined. Quote Link to comment Share on other sites More sharing options...
ffxpwns Posted May 23, 2012 Author Share Posted May 23, 2012 That is an awesome picture. $system is not defined within the context of that function. You said when you comment out line 18 you still get the error? I can only assume it changes to a different line number? Because you have $system->check_mysql in 3 places there, but $system is never defined. Thanks! Everyone love puppies. Now when I comment it out, no error is incited. But nothing happens to the balance / refer fields. Quote Link to comment Share on other sites More sharing options...
ffxpwns Posted May 24, 2012 Author Share Posted May 24, 2012 Also, when I use my old code (below) and I put the $refername or $referrer or whatever it is above the code, and I echo $query, it echos UPDATE DataBase_users SET balance = balance + 5 WHERE refer = ''. Almost as if it doesn't recognize it or something. And I'm sure my spelling is correct . I'm pretty sure PHP is out to get me. CODE: $query = "UPDATE ".$DBPrefix."users SET balance = balance + 5 WHERE refer = '".mysql_real_escape_string($referName)."'"; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); $gateway_data = mysql_fetch_assoc($res); $referName = $gateway_data['refer']; $query = "UPDATE ".$DBPrefix."users SET refer = '' WHERE nick = '".mysql_real_escape_string($referred)."'"; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); $gateway_data = mysql_fetch_assoc($res); $referred = $gateway_data['nick']; Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 24, 2012 Share Posted May 24, 2012 What is $system? Quote Link to comment Share on other sites More sharing options...
ffxpwns Posted May 24, 2012 Author Share Posted May 24, 2012 What is $system? In the common.inc.php, system is $system = new global_class(); Quote Link to comment Share on other sites More sharing options...
ffxpwns Posted May 25, 2012 Author Share Posted May 25, 2012 Would it work if I put it on another file and used it as in include? I'll try that and report back. Quote Link to comment Share on other sites More sharing options...
ffxpwns Posted May 26, 2012 Author Share Posted May 26, 2012 It did not. And, if it means anything, the permissions are 777. Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 29, 2012 Share Posted May 29, 2012 The error is telling you $system is not an object. 1 time it's because it's not within the function. The other time I don't know why, it's probably not actually defined. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.