Cetanu Posted August 20, 2009 Share Posted August 20, 2009 <?php include "db.php"; $result=mysql_query("SELECT * FROM rpg WHERE player='{$_SESSION['username']}'") or die(mysql_error()); while($row=mysql_fetch_array($result)){ if(!$_POST['submit']){ echo "<fieldset> <legend>Adding Statistics</legend> <form method='post' action='statadd.php'>"; echo $_SESSION['username'].", you currently have a ".$row['species']." character who has been named ".$row['name'].".<br/><br/> "; if($row['species']=="Aliens"){ echo "<strong>Aliens</strong> start off with 20 health and 20 defense; they also start out with 20 health and 20 stealth points. " .$row['name']." will start off with this much as well. In addition to this, you have been stocked with money in order to purchase items and upgrades. Aliens start off with 200 pieces of money, and you are free to spend in any way you like. Keep in mind that saving up money will lead to higher attacks, defenses, and stealth."; } elseif($row['species']=="Predator"){ echo "<strong>Predators</strong> start off with 25 health and 25 defense; in addition, they start with 25 health and 20 honor points. " .$row['name']. " is an unblooded hunter, and it is only proper that he start with that amount too. In addition, your Predator has 200 pieces of money, which you are free to use on buying upgrades, etc. Saving money will increase your chances of becoming stronger."; } if($row['species']=="Marines"){ echo "<strong>Marines</strong> are at a disadvantage due to the fact they are merely human. However, ".$row['name']." does have 20 attack and 10 defense, and they have 15 health and 20 melee points. Being that Marines are human and part of the marines, they are endowed with a fund of 500 pieces of money, and they are free to spend it on anything they like. A smart soldier will increase their power by saving money!"; } echo "<br/><br/>"; if($row['species']=="Aliens"){ echo "In addition, Aliens have several roles they can take on. Each role has its own benefits or weaknesses.<br/> <input type='radio' name='AStat' value='Drone'/> <strong>Drones</strong> are the workers of the hive. They cater the the Queen and to the eggs. The drones are stealthy creatures, yet weak and not meant for straight-on combat.<br/> <div style='color: red; text-align: center;'>Attack: -5 | Defense: +5 | Stealth: +10</div><br/> <input type='radio' name='AStat' value='Warrior'/> <strong>Warriors</strong> are the front-line defense of the hive. They fend off hostile creatures and will occasionally go scouting for hive resources.<br/> <div style='color: red; text-align: center;'>Attack: +5 | Defense: N/A | Stealth: -5</div><br/>"; } elseif($row['species']=="Predator"){ echo "The Predator race is fantastically advanced and complex. There are different positions with different benefits or weaknesses.<br/> <input type='radio' id='PStat' name='PStat' value='Freelancer'/> <strong>Freelancers</strong> are Predators that hunt alone without a clan. They do not abide by tough clan-law, however to not gain honor because of their lack of a clan.<br/> <div style='color: red; text-align: center;'>Attack: +5 | Defense: N/A | Honor: N/A</div><br/> <input type='radio' id='PStat' name='PStat' value='Bad Blood'/> <strong>Bad Bloods</strong> are Predators that follow no codes and have no clans. They are a disgrace, but often times they are stronger due to their lack of inhibition. A Bad Blood may find it hard to deal with other Predators, but at the same time may find it easier to kill prey. Their equipment is often times outdated. <br/> <div style='color: red; text-align: center;'>Attack: +5 | Defense: -5 | Honor: -10</div><br/> "; } if($row['species']=="Marines"){ echo "Marines are tight-knit and tech-savvy. They are the grunts of the military and willing to risk it all for their goals.<br/> <input type='radio' name='MStat' value='Sniper'/> <strong>Snipers</strong> are accurate with guns from far away, therefore boosting their attacks and defenses, but lowering their ability to use close-range weapons. That means that close-quarters are BAD.<br/> <div style='color: red; text-align: center;'>Attack: +5 | Defense: +5 | Melee: -10</div><br/> <input type='radio' name='MStat' value='Ballistic'/><strong> Ballistics</strong> are the fight-'em-up type of people. They are skilled with many weapons and have capabilities to use many weapon sets. In addition to that, they automatically are equipped with a grenade attack that boosts their attack by 10 points! Also, their armor is stronger. Unfortunately, ballistics cannot use long-range weapon sets.<br/> <div style='color: red; text-align: center;'>Attack: +5 | Defense: +10 | Melee: +5</div><br/>"; } echo "<br/><input type='submit' value='Submit Choice!' id='submit' name='submit'/><br/> </fieldset></form>"; } } if($_POST['submit']){ if($_POST['PStat']=="Freelancer"){ mysql_query("UPDATE rpg SET health=25 , defense=25 , attack=25 , honor=20 WHERE player='{$_SESSION['username']}'"); } if($_POST['PStat']=="Bad Blood"){ mysql_query("UPDATE rpg SET health=25 , defense=20 , attack=25 , honor=10 WHERE player='{$_SESSION['username']}'") ; } if($_POST['AStat']=="Drone"){ mysql_query("UPDATE rpg SET health=20 , defense=20 , attack=15 , stealth=30 WHERE player='{$_SESSION['username']}'") ; } if($_POST['AStat']=="Warrior"){ mysql_query("UPDATE rpg SET health=20 , defense=20 , attack=25 , stealth=15 WHERE player='{$_SESSION['username']}'"); } if($_POST['MStat']=="Sniper"){ mysql_query("UPDATE rpg SET health=15 , defense=25 , attack=20 , melee=10 WHERE player='{$_SESSION['username']}'") ; } if($_POST['MStat']=="Ballistic"){ mysql_query("UPDATE rpg SET health=15 , defense=30 , attack=20 , melee=25 WHERE player='{$_SESSION['username']}'") ; } $result=mysql_query("SELECT * FROM rpg WHERE player='{$_SESSION['username']}'") or die(mysql_error()); while($row=mysql_fetch_array($result)){ if($row['species'] == "Aliens" || "Predator"){ mysql_query('UPDATE rpg SET money=200 '); } elseif($row['species'] == "Marine"){ mysql_query('UPDATE rpg SET money=500 '); } } ?> In that code, I am doing a couple of things. This is for creating an RPG character, and it's my first BIG PHP project. >_> 1) <?php include "db.php"; $result=mysql_query("SELECT * FROM rpg WHERE player='{$_SESSION['username']}'") or die(mysql_error()); while($row=mysql_fetch_array($result)){ if(!$_POST['submit']){ echo "<fieldset> <legend>Adding Statistics</legend> <form method='post' action='statadd.php'>"; echo $_SESSION['username'].", you currently have a ".$row['species']." character who has been named ".$row['name'].".<br/><br/> "; if($row['species']=="Aliens"){ echo "<strong>Aliens</strong> start off with 20 health and 20 defense; they also start out with 20 health and 20 stealth points. " .$row['name']." will start off with this much as well. In addition to this, you have been stocked with money in order to purchase items and upgrades. Aliens start off with 200 pieces of money, and you are free to spend in any way you like. Keep in mind that saving up money will lead to higher attacks, defenses, and stealth."; } elseif($row['species']=="Predator"){ echo "<strong>Predators</strong> start off with 25 health and 25 defense; in addition, they start with 25 health and 20 honor points. " .$row['name']. " is an unblooded hunter, and it is only proper that he start with that amount too. In addition, your Predator has 200 pieces of money, which you are free to use on buying upgrades, etc. Saving money will increase your chances of becoming stronger."; } if($row['species']=="Marines"){ echo "<strong>Marines</strong> are at a disadvantage due to the fact they are merely human. However, ".$row['name']." does have 20 attack and 10 defense, and they have 15 health and 20 melee points. Being that Marines are human and part of the marines, they are endowed with a fund of 500 pieces of money, and they are free to spend it on anything they like. A smart soldier will increase their power by saving money!"; } Here I am explaining the three species based on a prior choice of one out of the three. (i.e. you pick Marines, and the Marines paragraph comes up) 2) <?php if($row['species']=="Aliens"){ echo "In addition, Aliens have several roles they can take on. Each role has its own benefits or weaknesses.<br/> <input type='radio' name='AStat' value='Drone'/> <strong>Drones</strong> are the workers of the hive. They cater the the Queen and to the eggs. The drones are stealthy creatures, yet weak and not meant for straight-on combat.<br/> <div style='color: red; text-align: center;'>Attack: -5 | Defense: +5 | Stealth: +10</div><br/> <input type='radio' name='AStat' value='Warrior'/> <strong>Warriors</strong> are the front-line defense of the hive. They fend off hostile creatures and will occasionally go scouting for hive resources.<br/> <div style='color: red; text-align: center;'>Attack: +5 | Defense: N/A | Stealth: -5</div><br/>"; } elseif($row['species']=="Predator"){ echo "The Predator race is fantastically advanced and complex. There are different positions with different benefits or weaknesses.<br/> <input type='radio' id='PStat' name='PStat' value='Freelancer'/> <strong>Freelancers</strong> are Predators that hunt alone without a clan. They do not abide by tough clan-law, however to not gain honor because of their lack of a clan.<br/> <div style='color: red; text-align: center;'>Attack: +5 | Defense: N/A | Honor: N/A</div><br/> <input type='radio' id='PStat' name='PStat' value='Bad Blood'/> <strong>Bad Bloods</strong> are Predators that follow no codes and have no clans. They are a disgrace, but often times they are stronger due to their lack of inhibition. A Bad Blood may find it hard to deal with other Predators, but at the same time may find it easier to kill prey. Their equipment is often times outdated. <br/> <div style='color: red; text-align: center;'>Attack: +5 | Defense: -5 | Honor: -10</div><br/> "; } if($row['species']=="Marines"){ echo "Marines are tight-knit and tech-savvy. They are the grunts of the military and willing to risk it all for their goals.<br/> <input type='radio' name='MStat' value='Sniper'/> <strong>Snipers</strong> are accurate with guns from far away, therefore boosting their attacks and defenses, but lowering their ability to use close-range weapons. That means that close-quarters are BAD.<br/> <div style='color: red; text-align: center;'>Attack: +5 | Defense: +5 | Melee: -10</div><br/> <input type='radio' name='MStat' value='Ballistic'/><strong> Ballistics</strong> are the fight-'em-up type of people. They are skilled with many weapons and have capabilities to use many weapon sets. In addition to that, they automatically are equipped with a grenade attack that boosts their attack by 10 points! Also, their armor is stronger. Unfortunately, ballistics cannot use long-range weapon sets.<br/> <div style='color: red; text-align: center;'>Attack: +5 | Defense: +10 | Melee: +5</div><br/>"; } echo "<br/><input type='submit' value='Submit Choice!' id='submit' name='submit'/><br/> </fieldset></form>"; } } if($_POST['submit']){ if($_POST['PStat']=="Freelancer"){ mysql_query("UPDATE rpg SET health=25 , defense=25 , attack=25 , honor=20 WHERE player='{$_SESSION['username']}'"); } if($_POST['PStat']=="Bad Blood"){ mysql_query("UPDATE rpg SET health=25 , defense=20 , attack=25 , honor=10 WHERE player='{$_SESSION['username']}'") ; } if($_POST['AStat']=="Drone"){ mysql_query("UPDATE rpg SET health=20 , defense=20 , attack=15 , stealth=30 WHERE player='{$_SESSION['username']}'") ; } if($_POST['AStat']=="Warrior"){ mysql_query("UPDATE rpg SET health=20 , defense=20 , attack=25 , stealth=15 WHERE player='{$_SESSION['username']}'"); } if($_POST['MStat']=="Sniper"){ mysql_query("UPDATE rpg SET health=15 , defense=25 , attack=20 , melee=10 WHERE player='{$_SESSION['username']}'") ; } if($_POST['MStat']=="Ballistic"){ mysql_query("UPDATE rpg SET health=15 , defense=30 , attack=20 , melee=25 WHERE player='{$_SESSION['username']}'") ; } $result=mysql_query("SELECT * FROM rpg WHERE player='{$_SESSION['username']}'") or die(mysql_error()); while($row=mysql_fetch_array($result)){ if($row['species'] == "Aliens" || "Predator"){ mysql_query('UPDATE rpg SET money=200 '); } elseif($row['species'] == "Marine"){ mysql_query('UPDATE rpg SET money=500 '); } } ?> Here I am letting them choose a class, and according to that I want to update my database with the appropriate attack, defense, etc. HOWEVER, the only thing that updates is the MONEY! (At the very end of the code) , I DO NOT KNOW WHY! <?php if($_POST['submit']){ if($_POST['PStat']=="Freelancer"){ mysql_query("UPDATE rpg SET health=25 , defense=25 , attack=25 , honor=20 WHERE player='{$_SESSION['username']}'"); } if($_POST['PStat']=="Bad Blood"){ mysql_query("UPDATE rpg SET health=25 , defense=20 , attack=25 , honor=10 WHERE player='{$_SESSION['username']}'") ; } if($_POST['AStat']=="Drone"){ mysql_query("UPDATE rpg SET health=20 , defense=20 , attack=15 , stealth=30 WHERE player='{$_SESSION['username']}'") ; } if($_POST['AStat']=="Warrior"){ mysql_query("UPDATE rpg SET health=20 , defense=20 , attack=25 , stealth=15 WHERE player='{$_SESSION['username']}'"); } if($_POST['MStat']=="Sniper"){ mysql_query("UPDATE rpg SET health=15 , defense=25 , attack=20 , melee=10 WHERE player='{$_SESSION['username']}'") ; } if($_POST['MStat']=="Ballistic"){ mysql_query("UPDATE rpg SET health=15 , defense=30 , attack=20 , melee=25 WHERE player='{$_SESSION['username']}'") ; } That is supposed to update my database according to chosen classes, but does nothing. Please help!!!! Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/171105-solved-php-wont-update/ Share on other sites More sharing options...
Garethp Posted August 20, 2009 Share Posted August 20, 2009 if(!mysql_query(YOUR QUERY)){echo mysql_error();} That'll help you find your error Link to comment https://forums.phpfreaks.com/topic/171105-solved-php-wont-update/#findComment-902333 Share on other sites More sharing options...
Cetanu Posted August 20, 2009 Author Share Posted August 20, 2009 Okay, thanks. Link to comment https://forums.phpfreaks.com/topic/171105-solved-php-wont-update/#findComment-902348 Share on other sites More sharing options...
Garethp Posted August 20, 2009 Share Posted August 20, 2009 Come back with the error if your still stuck Link to comment https://forums.phpfreaks.com/topic/171105-solved-php-wont-update/#findComment-902350 Share on other sites More sharing options...
Cetanu Posted August 20, 2009 Author Share Posted August 20, 2009 Nope. Got it. THANKS!!!! It was stupid. I forgot to create an extra column in my database, but your awesome little code fixed everything!!!!!!! XD THANKS Link to comment https://forums.phpfreaks.com/topic/171105-solved-php-wont-update/#findComment-902353 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.