Xyphon Posted January 18, 2009 Share Posted January 18, 2009 Sorry, I can't explain the problem in the subject. Here's the whole code: <?PHP include('top.php'); include('Connect.php'); $ID = $_COOKIE['UserID']; $ID = mysql_real_escape_string($ID); $Battle_Result= mysql_query("SELECT * FROM Battle_Information WHERE ID='$ID'"); $Battle_Rows= mysql_fetch_array($Battle_Result); $Battle_Result2= mysql_query("SELECT * FROM users WHERE ID='$ID'"); $Battle_Rows2= mysql_fetch_array($Battle_Result2); $Taijutsu= $Battle_Rows2['Taijutsu']; $Taijutsu = mysql_real_escape_string($Taijutsu); $Ninjutsu= $Battle_Rows2['Ninjutsu']; $Ninjutsu = mysql_real_escape_string($Ninjutsu); $Genjutsu= $Battle_Rows2['Genjutsu']; $Genjutsu = mysql_real_escape_string($Genjutsu); $Bloodline1= $Battle_Rows2['Bloodline']; $Bloodline1 = mysql_real_escape_string($Bloodline1); $Bloodline2= $Battle_Rows2['Bloodline2']; $Bloodline2 = mysql_real_escape_string($Bloodline2); $Bloodline3= $Battle_Rows2['Bloodline3']; $Bloodline3 = mysql_real_escape_string($Bloodline3); $Bloodline4= $Battle_Rows2['Bloodline4']; $Bloodline4 = mysql_real_escape_string($Bloodline4); $Bloodline5= $Battle_Rows2['Bloodline5']; $Bloodline5 = mysql_real_escape_string($Bloodline5); $Weapon= $Battle_Rows2['Weapon']; $Weapon = mysql_real_escape_string($Weapon); $Taijutsu_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Taijutsu'"); $Taijutsu_Rows= mysql_fetch_array($Taijutsu_Result); $Ninjutsu_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Ninjutsu'"); $Ninjutsu_Rows= mysql_fetch_array($Ninjutsu_Result); $Genjutsu_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Genjutsu'"); $Genjutsu_Rows= mysql_fetch_array($Genjutsu_Result); $Bloodline1_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Bloodline1'"); $Bloodline1_Rows= mysql_fetch_array($Bloodline1_Result); $Bloodline2_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Bloodline2'"); $Bloodline2_Rows= mysql_fetch_array($Bloodline2_Result); $Bloodline3_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Bloodline3'"); $Bloodline3_Rows= mysql_fetch_array($Bloodline3_Result); $Bloodline4_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Bloodline4'"); $Bloodline4_Rows= mysql_fetch_array($Bloodline4_Result); $Bloodline5_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Bloodline5'"); $Bloodline5_Rows= mysql_fetch_array($Bloodline5_Result); $Weapon_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Weapon'"); $Weapon_Rows= mysql_fetch_array($Weapon_Result); $Power= $Battle_Rows2['Power']; $Power = mysql_real_escape_string($Power); $Max_HP= $Battle_Rows2['Max_HP']; $Max_HP= mysql_real_escape_string($Max_HP); if(!isset($ID)) { echo "Sorry, you must be logged in to view this page"; include('bottom.php'); exit; } if($Battle_Rows['Enemy_Name']=="") { echo "Sorry, you aren't in a battle.."; } else { $Submit = $_GET['Type']; if(!$Submit) { echo " <html> <center> <table border='3' bordercolor='red' width='550' height='300'><td><center> <table border='0' width='550'><td><center>" . $Battle_Rows['Enemy_Name'] . "<br> HP: " . $Battle_Rows['Enemy_HP'] . "/" . $Battle_Rows['Enemy_Max_HP'] . " Chakra: " . $Battle_Rows['Enemy_Chakra'] . "/" . $Battle_Rows['Enemy_Max_Chakra'] . "</td></table><br><br><br><br> <table border='1' width='550'><td><center>Taijutsu:<br><a href='battle.php?Type=Taijutsu'>" . $Battle_Rows2['Taijutsu'] . "</a></td><td>Ninjutsu:<br><a href='battle.php?Type=Ninjutsu'>" . $Battle_Rows2['Ninjutsu'] . "</a></td><font size='3'><td>Genjutsu:<br><a href='battle.php?Type=Genjutsu'>" . $Battle_Rows2['Genjutsu']. "</a></td><td>Bloodline:<br><a href='battle.php?Type=Bloodline1'>" . $Battle_Rows2['Bloodline'] . "</a></td><td>Weapon:<br><a href='battle.php?Type=Weapon'>" . $Battle_Rows2['Weapon'] . "</a></td></table><br><table border='0' width='550'> <td><center>" . $Battle_Rows2['Username'] . "<br> HP: " . $Battle_Rows2['HP'] . "/" . $Battle_Rows2['Max_HP'] . " Chakra: " . $Battle_Rows2['Chakra'] . "/" . $Battle_Rows2['Max_Chakra'] . "</td></table></td></table>"; } else { if($Submit=='Taijutsu') { $EnemyRand= rand(1, 4); $GenjutsuE= $Battle_Rows['Enemy_Genjutsu']; $GenjutsuE= mysql_real_escape_string($GenjutsuE); $NinjutsuE= $Battle_Rows['Enemy_Ninjutsu']; $NinjutsuE= mysql_real_escape_string($NinjutsuE); $TaijutsuE= $Battle_Rows['Enemy_Taijutsu']; $TaijutsuE= mysql_real_escape_string($TaijutsuE); $WeaponE= $Battle_Rows['Enemy_Weapon']; $WeaponE= mysql_real_escape_string($WeaponE); $Taijutsu_Enemy_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$TaijutsuE'"); $Taijutsu_Enemy_Rows= mysql_fetch_array($Taijutsu_Enemy_Result); $Ninjutsu_Enemy_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$NinjutsuE'"); $Ninjutsu_Enemy_Rows= mysql_fetch_array($Ninjutsu_Enemy_Result); $Genjutsu_Enemy_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$GenjutsuE'"); $Genjutsu_Enemy_Rows= mysql_fetch_array($Genjutsu_Enemy_Result); $Weapon_Enemy_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$WeaponE'"); $Weapon_Enemy_Rows= mysql_fetch_array($Weapon_Enemy_Result); if($EnemyRand=="4") { $Enemy_Move= $NinjutsuE; $EnemyDamage1= $Ninjutsu_Enemy_Rows['Jutsu_Power']; $EnemyDamage1= mysql_real_escape_string($EnemyDamage1); $Ninjutsupower= $Battle_Rows['Ninjutsu_Power']; $Ninjutsupower= mysql_real_escape_string($Ninjutsupower); $EnemyPower= $Battle_Rows['Enemy_Power']; $EnemyPower= mysql_real_escape_string($EnemyPower); $EnemyDamage2= round(($EnemyDamage1 + Ninjutsupower) + $EnemyPower); $EnemyDamage3= round($EnemyDamage2 / 5); $HP= $Battle_Rows2['HP']; $HP= mysql_real_escape_string($HP); $HP= round($HP - $EnemyDamage3); $Defense= $Ninjutsu_Enemy_Rows['Defense']; $Defense= mysql_real_escape_string($Defense); if($EnemyDamage1=="0") { $EnemyDamage3= 0; } if($HP < 0) { $HP= 0; } } elseif($EnemyRand=="3") { $Enemy_Move= $TaijutsuE; $EnemyDamage1= $Taijutsu_Enemy_Rows['Jutsu_Power']; $EnemyDamage1= mysql_real_escape_string($EnemyDamage1); $Taijutsupower= $Battle_Rows['Taijutsu_Power']; $Taijutsupower= mysql_real_escape_string($Taijutsupower); $EnemyPower= $Battle_Rows['Enemy_Power']; $EnemyPower= mysql_real_escape_string($EnemyPower); $EnemyDamage2= round(($EnemyDamage1 + Taijutsupower) + $EnemyPower); $EnemyDamage3= round($EnemyDamage2 / 5); $HP= $Battle_Rows2['HP']; $HP= mysql_real_escape_string($HP); $HP= round($HP - $EnemyDamage3); $Defense= $Taijutsu_Enemy_Rows['Defense']; $Defense= mysql_real_escape_string($Defense); if($HP < 0) { $HP= 0; } } elseif($EnemyRand=="2") { $Enemy_Move= $GenjutsuE; $EnemyDamage1= $Genjutsu_Enemy_Rows['Jutsu_Power']; $EnemyDamage1= mysql_real_escape_string($EnemyDamage1); $Genjutsupower= $Battle_Rows['Genjutsu_Power']; $Genjutsupower= mysql_real_escape_string($Genjutsupower); $EnemyPower= $Battle_Rows['Enemy_Power']; $EnemyPower= mysql_real_escape_string($EnemyPower); $EnemyDamage2= round(($EnemyDamage1 + Genjutsupower) + $EnemyPower); $EnemyDamage3= round($EnemyDamage2 / 5); $HP= $Battle_Rows2['HP']; $HP= mysql_real_escape_string($HP); $HP= round($HP - $EnemyDamage3); $Defense= $Genjutsu_Enemy_Rows['Defense']; $Defense= mysql_real_escape_string($Defense); if($EnemyDamage1=="0") { $EnemyDamage3= 0; } if($HP < 0) { $HP= 0; } } else { $Enemy_Move= $WeaponE; $EnemyDamage1= $Weapon_Enemy_Rows['Jutsu_Power']; $EnemyDamage1= mysql_real_escape_string($EnemyDamage1); $Weaponpower= $Battle_Rows['Weapon_Power']; $Weaponpower= mysql_real_escape_string($Weaponpower); $EnemyPower= $Battle_Rows['Enemy_Power']; $EnemyPower= mysql_real_escape_string($EnemyPower); $EnemyDamage2= round(($EnemyDamage1 + Weaponpower) + $EnemyPower); $EnemyDamage3= round($EnemyDamage2 / 5); $HP= $Battle_Rows2['HP']; $HP= mysql_real_escape_string($HP); $HP= round($HP - $EnemyDamage3); $Defense= $Weapon_Enemy_Rows['Defense']; $Defense= mysql_real_escape_string($Defense); if($HP < 0) { $HP= 0; } } $Damage1= $Taijutsu_Rows['Jutsu_Power']; $Damage1= mysql_real_escape_string($Damage1); $Taijutsupower= $Battle_Rows2['Taijutsu_Power']; $Taijutsupower= mysql_real_escape_string($Taijutsupower); $Damage2= round(($Damage1 + $Taijutsupower) + $Power); $Damage3= round($Damage2 / 5); if($Defense=="Yes") { $Damage3="0"; $DefenseMessage="It stopped you from doing damage!"; } $Enemy_HP= round($Enemy_HP - $Damage3); $Enemy_MHP= $Battle_Rows['Enemy_Max_HP']; if($Enemy_HP < 0) { $Enemy_HP= 0; } mysql_query("UPDATE Battle_Information SET Enemy_HP='$Enemy_HP' WHERE ID='$ID'"); mysql_query("UPDATE users SET HP='$HP' WHERE ID='$ID'"); echo "<html> <center> <table border='3' bordercolor='red' width='550' height='300'><td><center> <table border='0' width='550'><td><center>" . $Battle_Rows['Enemy_Name'] . "<br> HP: " . $Enemy_HP . "/" . $Battle_Rows['Enemy_Max_HP'] . " Chakra: " . $Battle_Rows['Enemy_Chakra'] . "/" . $Battle_Rows['Enemy_Max_Chakra'] . "</td></table><br><br><br><br> <table border='1' width='550'><td><center>Taijutsu:<br><a href='battle.php?Type=Taijutsu'>" . $Battle_Rows2['Taijutsu'] . "</a></td><td>Ninjutsu:<br><a href='battle.php?Type=Ninjutsu'>" . $Battle_Rows2['Ninjutsu'] . "</a></td><font size='3'><td>Genjutsu:<br><a href='battle.php?Type=Genjutsu'>" . $Battle_Rows2['Genjutsu']. "</a></td><td>Bloodline:<br><a href='battle.php?Type=Bloodline1'>" . $Battle_Rows2['Bloodline'] . "</a></td><td>Weapon:<br><a href='battle.php?Type=Weapon'>" . $Battle_Rows2['Weapon'] . "</a></td></table><br><table border='0' width='550'> <td><center>" . $Battle_Rows2['Username'] . "<br> HP: " . $Battle_Rows2['HP'] . "/" . $Battle_Rows2['Max_HP'] . " Chakra: " . $Battle_Rows2['Chakra'] . "/" . $Battle_Rows2['Max_Chakra'] . "</td></table>The Enemy used $Enemy_Move. $DefenseMessage<br>It did $EnemyDamage3 damage!<br>You did $Damage3 damage!"; if($Enemy_HP=="0") { echo "<html><font size='3'> You have defeated the enemy!</font>"; $EXP_Gained= round($Enemy_MHP * 1.2); echo "<br>You gained $EXP_Gained EXP!"; $EXP= $Battle_Rows2['EXP']; $EXP= mysql_real_escape_string($EXP); $Total_EXP= round($EXP + $EXP_Gained); mysql_query("UPDATE users SET EXP='$Total_EXP' WHERE ID='$ID'"); $EXP2= $Battle_Rows2['EXP']; $EXP2= mysql_real_escape_string($EXP2); $NEXP= $Battle_Rows2['NEXP']; $NEXP= mysql_real_escape_string($NEXP); if($EXP2 >= $NEXP) { $EXP2= round($EXP2 - $NEXP); $NEXP= round($NEXP * 1.5); $Level= $Battle_Rows2['Level']; $Level= mysql_real_escape_string($Level); $Level2= round($Level + 1); $Statpoints= $Battle_Rows2['Stat_Points']; $Statpoints= mysql_real_escape_string($Statpoints); $Statpoints2= round($Statpoints + 3); $Max_HP2= round($Max_HP * 1.2); $Power2 = round($Power * 1.2); $Chakra= $Battle_Rows2['Max_Chakra']; $Chakra= mysql_real_escape_string($Chakra); $Chakra2= round($Chakra + 1); mysql_query("UPDATE users SET EXP=$EXP2, NEXP=$NEXP, Level=$Level2, Stat_Points=$Statpoints2, Max_HP=$Max_HP, HP=$Max_HP, Max_Chakra=$Chakra2, Chakra=$Chakra2, Power=$Power2 WHERE ID='$ID'"); echo "<br>You have gained a level!"; echo "<br>Level: $Level2<br />Statpoints: +3<br>HP: $Max_HP2<br>Power: $Power2<br>Chakra: $Chakra2"; } mysql_query("DELETE FROM Battle_Information WHERE ID='$ID'"); } } elseif($Submit=='Ninjutsu') { echo "Ninjutsu!"; } elseif($Submit=='Genjutsu') { echo "Genjutsu!"; } elseif($Submit=='Bloodline1') { echo "Bloodline1!"; } else { echo "Weapon!"; } } } ?> " Chakra: " . $Battle_Rows2['Chakra'] . "/" . $Battle_Rows2['Max_Chakra'] . "</td></table>The Enemy used $Enemy_Move. $DefenseMessage<br>It did $EnemyDamage3 damage!<br>You did $Damage3 damage!"; if($Enemy_HP=="0") { echo "<html><font size='3'> You have defeated the enemy!</font>"; $EXP_Gained= round($Enemy_MHP * 1.2); echo "<br>You gained $EXP_Gained EXP!"; $EXP= $Battle_Rows2['EXP']; $EXP= mysql_real_escape_string($EXP); $Total_EXP= round($EXP + $EXP_Gained); mysql_query("UPDATE users SET EXP='$Total_EXP' WHERE ID='$ID'"); $EXP2= $Battle_Rows2['EXP']; $EXP2= mysql_real_escape_string($EXP2); $NEXP= $Battle_Rows2['NEXP']; $NEXP= mysql_real_escape_string($NEXP); if($EXP2 >= $NEXP) { $EXP2= round($EXP2 - $NEXP); $NEXP= round($NEXP * 1.5); $Level= $Battle_Rows2['Level']; $Level= mysql_real_escape_string($Level); $Level2= round($Level + 1); $Statpoints= $Battle_Rows2['Stat_Points']; $Statpoints= mysql_real_escape_string($Statpoints); $Statpoints2= round($Statpoints + 3); $Max_HP2= round($Max_HP * 1.2); $Power2 = round($Power * 1.2); $Chakra= $Battle_Rows2['Max_Chakra']; $Chakra= mysql_real_escape_string($Chakra); $Chakra2= round($Chakra + 1); mysql_query("UPDATE users SET EXP=$EXP2, NEXP=$NEXP, Level=$Level2, Stat_Points=$Statpoints2, Max_HP=$Max_HP, HP=$Max_HP, Max_Chakra=$Chakra2, Chakra=$Chakra2, Power=$Power2 WHERE ID='$ID'"); and thats where it goes wrong. See how it says if(EXP >= NEXP) Well when all that happens, it doesnt display, even if the EXP is bigger. Basically, for some reason, it doesnt register the info until the next page (It works next time I win a battle, or when the HP=="0"). Why doesn't it register the info right after it happens? Can you fix this up for me? Quote Link to comment https://forums.phpfreaks.com/topic/141368-solved-help/ Share on other sites More sharing options...
Xyphon Posted January 18, 2009 Author Share Posted January 18, 2009 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/141368-solved-help/#findComment-740030 Share on other sites More sharing options...
Philip Posted January 18, 2009 Share Posted January 18, 2009 I've got to be honest with you, I looked at your other thread and this one. Your code is really hard to read through, and you're not providing a lot of background information on what is supposed to happen, how it happens, etc. Take it as constructive criticism, but you have a lot of inefficient code. Quote Link to comment https://forums.phpfreaks.com/topic/141368-solved-help/#findComment-740050 Share on other sites More sharing options...
premiso Posted January 18, 2009 Share Posted January 18, 2009 My bet is you are not re-querying the data before you run that if so you are using the old data. Quote Link to comment https://forums.phpfreaks.com/topic/141368-solved-help/#findComment-740052 Share on other sites More sharing options...
Flames Posted January 18, 2009 Share Posted January 18, 2009 Premiso is right, your finding the info then updating then echoing the info without reaquiring the info. Quote Link to comment https://forums.phpfreaks.com/topic/141368-solved-help/#findComment-740058 Share on other sites More sharing options...
Xyphon Posted January 18, 2009 Author Share Posted January 18, 2009 Thank you guys. KingPhilip: Well I use notepad 2 so neatness isnt a problem, the brackets are highlighted red when it opens and closes. I know I'm not neat, I've practiced mainly in just coding, not neatness, normally I dont need this forum I dont code that much, I'm only 13. Thanks to all you guys my battle system is done! Quote Link to comment https://forums.phpfreaks.com/topic/141368-solved-help/#findComment-740066 Share on other sites More sharing options...
Flames Posted January 18, 2009 Share Posted January 18, 2009 Xyphon age doesnt matter, i started PHP when i was 10, im currently 14 and work on a game of my own. All you gotta do is think about how everything works and neatness is one of the most important things in coding, seeing as its a game no doubt you will eventually go back and make improvements to the battle system, and then you wont be able to make the changes. Quote Link to comment https://forums.phpfreaks.com/topic/141368-solved-help/#findComment-740072 Share on other sites More sharing options...
Xyphon Posted January 20, 2009 Author Share Posted January 20, 2009 I never said it mattered, I ment I haven't been coding for too long, that was basically my point. I dont need neatness- unless someone ELSE is editing it. I can fix errors and stuff as long as it isnt coded like this: if(Blah) { echo "Hi"; } I need it to be seperate lines. Quote Link to comment https://forums.phpfreaks.com/topic/141368-solved-help/#findComment-741544 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.