Crediting script MAJOR problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thefreebielife
Forum Contributor
Posts: 126
Joined: Thu Apr 26, 2007 2:59 pm

Crediting script MAJOR problem

Post by thefreebielife »

so i tried updating this script to credit values such as 10, 20, etc. to users "ostatus". But it still only credits 1, and only 1. and the worst part, if a user does more then 1 offer, theyre account still only gets credited 1. please let me know what i did wrong.

Code: Select all

	if ($status == 1) {

		//Added following for crediting Logic
		if($ip == "75.126.157.90" or "204.10.140.62" or "204.10.140.63") $sql="select oWeight from offers where oCampID='" . $campaign . "'";
		else $sql="select oWeight from offers where oName='" . $name . "'";
		$result = mysql_query($sql);
		$oWeight=0.0;
		if($r=mysql_fetch_array($result))
		{	
			if($r['oWeight']=='1')
			$oWeight=1;
			if($r['oWeight']=='5')
			$oWeight=5;
			if($r['oWeight']=='10')
			$oWeight=10;
			if($r['oWeight']=='20')
			$oWeight=15;
			if($r['oWeight']=='25')
			$oWeight=25;
			if($r['oWeight']=='30')
			$oWeight=30;
			if($r['oWeight']=='35')
			$oWeight=35;
			if($r['oWeight']=='45')
			$oWeight=40;
			if($r['oWeight']=='50')
			$oWeight=50;
			if($r['oWeight']=='60')
			$oWeight=60;
		}

		//Updating ostatus with weightage rather then 1 or 0.
		$totalO=0;
		$currOStatus=mysql_result(mysql_query("SELECT `ostatus` FROM `users` WHERE `uid`='$sid'"),0);
		if(($currOStatus+$oWeight)>1) $totalO=100;
		else $totalO=$currOStatus+$oWeight; 	


		$query="UPDATE users SET ostatus=" . $totalO . " WHERE uId='$sid'";
		mysql_query($query) or die("Could not update status because ".mysql_error());
		echo "<Center>Credit Given</center><br><br>";
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

mysql_fetch_array() does not return an associative array.

You want mysql_fetch_assoc() or, if your PHP is old, mysql_fetch_array($foo, MYSQL_ASSOC).


And a suggestion... Use else-if statements instead of just if statements. If one of those is true, the others cant be, so make sure your script is aware.
thefreebielife
Forum Contributor
Posts: 126
Joined: Thu Apr 26, 2007 2:59 pm

Post by thefreebielife »

would this be better:

Code: Select all


	if ($status == 1) {

		//Added following for crediting Logic
		if($ip == "75.126.157.90" or "204.10.140.62" or "204.10.140.63") $sql="select oWeight from offers where oCampID='" . $campaign . "'";
		else $sql="select oWeight from offers where oName='" . $name . "'";
		$result = mysql_query($sql);
		$oWeight=0.0;
		if($r=mysql_fetch_assoc($result))
		{	
			if($r['oWeight']=='1')
			$oWeight=1;
			else if($r['oWeight']=='5')
			$oWeight=5;
			else if($r['oWeight']=='10')
			$oWeight=10;
			else if($r['oWeight']=='20')
			$oWeight=15;
			else if($r['oWeight']=='25')
			$oWeight=25;
			else if($r['oWeight']=='30')
			$oWeight=30;
			else if($r['oWeight']=='35')
			$oWeight=35;
			else if($r['oWeight']=='45')
			$oWeight=40;
			else if($r['oWeight']=='50')
			$oWeight=50;
			else if($r['oWeight']=='60')
			$oWeight=60;
		}

		//Updating ostatus with weightage rather then 1 or 0.
		$totalO=0;
		$currOStatus=mysql_result(mysql_query("SELECT `ostatus` FROM `users` WHERE `uid`='$sid'"),0);
		if(($currOStatus+$oWeight)>1) $totalO=100;
		else $totalO=$currOStatus+$oWeight; 	
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mysql_fetch_array() returns both an associative array and numeric array when not specifying which you want as a second parameter.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

feyd wrote:mysql_fetch_array() returns both an associative array and numeric array when not specifying which you want as a second parameter.
I stand corrected.


Have you tried echoing $totalO, $currOStatus, and $oWeight, and seeing which one is wrong...?
thefreebielife
Forum Contributor
Posts: 126
Joined: Thu Apr 26, 2007 2:59 pm

Post by thefreebielife »

$totalO, $currOStatus, and $oWeight are just variables for this script.

$ostatus is what should be updated by this script but its not working right (anymore). When this was written it was meant to only go to ostatus = 1 MAX
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Yes, and as far as I see, the ONLY variables for this script. Therefore, if you're getting the wrong number, one of them are probably the cause of the problem.
thefreebielife
Forum Contributor
Posts: 126
Joined: Thu Apr 26, 2007 2:59 pm

Post by thefreebielife »

do you think totalO is the problem? i changed that to 100
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Well, until you do some debugging, I can't really make heads or tails of it.
thefreebielife
Forum Contributor
Posts: 126
Joined: Thu Apr 26, 2007 2:59 pm

Post by thefreebielife »

well i used phped's debug and didnt get any problems. im so confused but that you for your help
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

By debugging, I simply mean echoing the values that you're dealing with. Either the values are incorrect, or they way that you are treating them is incorrect. So.. You should figure out which it is.
Post Reply