SirChick Posted October 2, 2007 Share Posted October 2, 2007 I have a script that what ever you input will determine the amount added to a field....but it keeps going to the die after the query for the number of rows affected. // this does get the value from the form so all is good here $StrengthInput = mysql_real_escape_string($_POST['strength']); $Total = ($StrengthInput) * 5; $EnergySubtract = $Total; If ($Total > $CurrentEnergy) { Die ('You do not have enough energy!'); } Else{ include("houseinclude.php"); $HouseType = $houserow["HouseType"]; If ($HouseType == 'Blanket') { $percentage1 = 0.001; } $PercentageAddOn = array(); $PercentageAddOn[] = 2; $PercentageAddOn[] = 5; $PercentageAddOn[] = 6; $PercentageAddOn[] = 1; $PercentageAddOn[] = 1; $PercentageKey = array_rand($PercentageAddOn); $PercentageAddOn = $PercentageResults[$PercentageKey]; $NewPercentageStrength = $StrengthInput*($PercentageAddOn + $percentage1); } If ($StrengthInput > 0){ //New strength seems to always = 0 no idea why $NewStrength = $Strength * (1 + $NewPercentageStrength/100); $StatStrengthGain = $NewStrength - $Strength; $addstrength = "UPDATE userregistration SET Strength=$NewStrength WHERE UserID='{$_SESSION['Current_User']}'"; $resultresult = mysql_query($addstrength) or die(mysql_error()); If (mysql_affected_rows() == 0) { die('Error ID 0001, contact admin on the Civilian forums immediatly about this error!'); } } the result i keep getting is die('Error ID 0001, contact admin on the Civilian forums immediatly about this error!'); cant work out why Quote Link to comment https://forums.phpfreaks.com/topic/71561-script-keeps-going-to-die/ Share on other sites More sharing options...
pocobueno1388 Posted October 2, 2007 Share Posted October 2, 2007 Try changing this: If (mysql_affected_rows() == 0) { To if (mysql_num_rows($resultresult) < 1) { Quote Link to comment https://forums.phpfreaks.com/topic/71561-script-keeps-going-to-die/#findComment-360295 Share on other sites More sharing options...
SirChick Posted October 2, 2007 Author Share Posted October 2, 2007 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\gymstat.php on line 119 This was the result. Quote Link to comment https://forums.phpfreaks.com/topic/71561-script-keeps-going-to-die/#findComment-360366 Share on other sites More sharing options...
MadTechie Posted October 2, 2007 Share Posted October 2, 2007 change $addstrength = "UPDATE userregistration SET Strength=$NewStrength WHERE UserID='{$_SESSION['Current_User']}'"; to $addstrength = "UPDATE userregistration SET Strength='$NewStrength' WHERE UserID='{$_SESSION['Current_User']}'"; Quote Link to comment https://forums.phpfreaks.com/topic/71561-script-keeps-going-to-die/#findComment-360406 Share on other sites More sharing options...
SirChick Posted October 2, 2007 Author Share Posted October 2, 2007 Still goes to die... I believe ive narrowed it down to this line: $NewStrength = ($StrengthInput) * (1 + $NewPercentageStrength/100); cos when i echo $NewStrength it echos "0" so that would mean the query updates nothing and thus it dies... Is my maths syntax correct... it must be =/ Quote Link to comment https://forums.phpfreaks.com/topic/71561-script-keeps-going-to-die/#findComment-360420 Share on other sites More sharing options...
BlueSkyIS Posted October 2, 2007 Share Posted October 2, 2007 you shouldn't use mysql_real_escape_string() on $_POST['strength'] before you use it for math or comparisons. why do you escape that value anyway? Do you expect characters that need to be escaped? if so, which ones? Quote Link to comment https://forums.phpfreaks.com/topic/71561-script-keeps-going-to-die/#findComment-360435 Share on other sites More sharing options...
BlueSkyIS Posted October 2, 2007 Share Posted October 2, 2007 $NewStrength = $Strength * (1 + $NewPercentageStrength/100); Is $Strength ever set? if not, there's your 0. Quote Link to comment https://forums.phpfreaks.com/topic/71561-script-keeps-going-to-die/#findComment-360439 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.