Page 1 of 1

Crediting script MAJOR problem

Posted: Mon May 28, 2007 7:35 am
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>";

Posted: Mon May 28, 2007 7:41 am
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.

Posted: Mon May 28, 2007 7:53 am
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; 	

Posted: Mon May 28, 2007 7:54 am
by feyd
mysql_fetch_array() returns both an associative array and numeric array when not specifying which you want as a second parameter.

Posted: Mon May 28, 2007 8:01 am
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...?

Posted: Mon May 28, 2007 8:10 am
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

Posted: Mon May 28, 2007 8:15 am
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.

Posted: Mon May 28, 2007 8:40 am
by thefreebielife
do you think totalO is the problem? i changed that to 100

Posted: Mon May 28, 2007 8:42 am
by superdezign
Well, until you do some debugging, I can't really make heads or tails of it.

Posted: Mon May 28, 2007 8:44 am
by thefreebielife
well i used phped's debug and didnt get any problems. im so confused but that you for your help

Posted: Mon May 28, 2007 8:49 am
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.