Cetanu Posted August 20, 2009 Share Posted August 20, 2009 <?php elseif($_POST['equip']){ $result=mysql_query("SELECT * FROM rpg WHERE player='{$_SESSION['username']}'") or die(mysql_error()); while($row=mysql_fetch_array($result)){ if($_POST['PWeapon']=="Ranged"){ $anum=5; $attack = $row['attack']+$anum; $defense = $row['defense']+$anum; $honor = $row['honor']-$anum; mysql_query("UPDATE rpg SET attack='{$attack}' , defense='{$defense}' , honor='{$honor}' WHERE player='{$_SESSION['username']}'"); } } } ?> In that block of code I have made an error, and after tediously searching I dunno what it is. I think it has something to do with the UPDATE statement. I dunno, though. Quote Link to comment https://forums.phpfreaks.com/topic/171167-solved-i-cant-find-the-error-can-you/ Share on other sites More sharing options...
ignace Posted August 20, 2009 Share Posted August 20, 2009 What is the error you get? And is this the entire code? Quote Link to comment https://forums.phpfreaks.com/topic/171167-solved-i-cant-find-the-error-can-you/#findComment-902628 Share on other sites More sharing options...
Cetanu Posted August 20, 2009 Author Share Posted August 20, 2009 What is the error you get? And is this the entire code? I don't get an error, I get the white screen of doom that happens when I mess up a variable or something. That isn't the whole code, just the block causing the error. The whole code is: <?php include "db.php"; $result=mysql_query("SELECT * FROM rpg WHERE player='{$_SESSION['username']}'") or die(mysql_error()); while($row=mysql_fetch_array($result)){ echo $_SESSION['username'].", you have reached nearly the final stage of character creation! Here we must equip your character with weapons or armor so they are ready to brawl!!!"; echo "<form action='equip.php' method='post'><fieldset><legend>Choose Equipment for ".$row['name']."!</legend>"; if(!$_POST['equip']){ if($row['species']=="Alien"){ echo "Aliens must choose a primary and secondary weapon considering they do not have technology available to them...<br/>"; echo "<input type='checkbox' name='AWeapon[]' value='Tail'/> The <strong>alien tail</strong> is a formidable weapon for anything a xenomorph is fighting. The tail gives the alien range, and it is razor sharp. <br/> <div style='color: red;'>+5 Attack</div> <br/> <input type='checkbox' name='AWeapon[]' value='Inner Jaws'/> The <strong>inner jaws</strong> of an alien are the trademark of the creature. They are a tongue-like protrusion that extends out of the mouth and can pierce metal.<br/> <div style='color: red;'>+5 Attack | -5 Defense | -5 Sneak </div><br/> <input type='checkbox' name='AWeapon[]' value='Claws'/> The <strong>claws</strong> of an alien can tear through metal, flesh, and bone. They are useful, but not always effective when sneaking about.<br/> <div style='color: red;'>+5 Attack | -5 Defense | -10 Sneak</div><br/>"; } } if($row['species']=="Predator"){ echo "Predators have a bunch of weapons available, but novice hunters cannot use all of these. Instead, you must choose weapon sets for your character.<br/>"; echo "<input type='radio' name='PWeapon' value='Ranged'/> The <strong>Ranged Weapon Set</strong> includes the netgun, speargun, and smart disc. It is good for those not willing to get their hands dirty, and that like to have the upper hand.<br/> <div style='color: red;'>+5 Attack | +5 Defense | -5 Honor</div><br/> <input type='radio' name='PWeapon' value='Melee'/> The <strong>Melee Weapon Set</strong> includes the wristblades, the spear, and the whip. It is for those who seek to be the best-of-the-best in close-combat, and for those who wish to maintain honor.<br/> <div style='color: red;'>+5 Attack | -5 Defense | +5 Honor</div><br/>"; } if($row['species']=="Marines"){ echo "The Marines are skilled with many weapons. They mostly use human weapons, which are weaker than Predator and Alien weaponry, yet they still get the job done! Please select a primary and a secondary weapon.<br/>"; echo "<input type='checkbox' name='MWeapons[]' value='Rifle'/> The <strong>M41 Pulse Rifle</strong> is standard for Marines. It is a ranged weapon, and can be upgraded with a grenade launcher.<br/> <input type='checkbox' name='MWeapons[]' value='Launcher'/> Outfit with Grenade Launcher for 100 pieces of money?<br/> <div style='color: red;'>+5 Attack | +5 Defense | -5 Melee</div> WITH GRENADE LAUNCHER: <div style='color: red;'>+10 Attack | +5 Defense | -10 Melee</div> <br/> <input type='checkbox' name='MWeapons[]' value='Flamethrower'/> The <strong>Flamethrower</strong> is good for mid-ranged targets, and can also provide extra defense until the flames die down.<br/> <div style='color: red;'>+5 Attack | +5 Defense | +5 Melee</div><br/> <input type='checkbox' name='MWeapons[]' value='Pistol'/> <strong>Standard Issue Pistols</strong> are not good for far targets, but they will pierce Alien chitin. <br/> <div style='color: red;'>+5 Attack | -5 Defense | +5 Melee</div><br/>"; } echo "<input type='submit' value='Equip Character' name='equip'/>"; } elseif($_POST['equip']){ $result=mysql_query("SELECT * FROM rpg WHERE player='{$_SESSION['username']}'") or die(mysql_error()); while($row=mysql_fetch_array($result)){ if($_POST['PWeapon']=="Ranged"){ $anum=5; $attack = $row['attack']+$anum; $defense = $row['defense']+$anum; $honor = $row['honor']-$anum; mysql_query("UPDATE rpg SET attack='{$attack}' , defense='{$defense}' , honor='{$honor}' WHERE player='{$_SESSION['username']}'"); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/171167-solved-i-cant-find-the-error-can-you/#findComment-902629 Share on other sites More sharing options...
Monadoxin Posted August 20, 2009 Share Posted August 20, 2009 I never saw that bracket stuff in a query, or some of the other things you have in there before, that might be the problem. I have never used a '+', mostly '.', adding to a string. The minus sign looks wrong too. I am not sure though. Though maybe I am wrong about that stuff. I don't see anything else suspicious looking. Quote Link to comment https://forums.phpfreaks.com/topic/171167-solved-i-cant-find-the-error-can-you/#findComment-902631 Share on other sites More sharing options...
Cetanu Posted August 20, 2009 Author Share Posted August 20, 2009 They're supposed to be adding 5 to the respective value. Maybe I did that wrong. >.> Quote Link to comment https://forums.phpfreaks.com/topic/171167-solved-i-cant-find-the-error-can-you/#findComment-902634 Share on other sites More sharing options...
Monadoxin Posted August 20, 2009 Share Posted August 20, 2009 My apologies, that part is correct, I was not thinking. However, have you tried using debugging with errors displayed? Quote Link to comment https://forums.phpfreaks.com/topic/171167-solved-i-cant-find-the-error-can-you/#findComment-902641 Share on other sites More sharing options...
Cetanu Posted August 20, 2009 Author Share Posted August 20, 2009 I can't because the pages just goes to a blank white. Here, look: http://mythscape.freezoka.com/chrisrpg/equip.php It just is...white. Nothing shows unless I remove that block of code. Quote Link to comment https://forums.phpfreaks.com/topic/171167-solved-i-cant-find-the-error-can-you/#findComment-902644 Share on other sites More sharing options...
ignace Posted August 20, 2009 Share Posted August 20, 2009 Using arrays in string ain't a good idea altough it is possible. Try using: $query = 'SELECT * FROM rpg WHERE player = \'%s\''; $fquery = sprintf($query, $_SERVER['username']); $result = mysql_query($fquery, $db); Quote Link to comment https://forums.phpfreaks.com/topic/171167-solved-i-cant-find-the-error-can-you/#findComment-902645 Share on other sites More sharing options...
Cetanu Posted August 20, 2009 Author Share Posted August 20, 2009 Using arrays in string ain't a good idea altough it is possible. Try using: $query = 'SELECT * FROM rpg WHERE player = \'%s\''; $fquery = sprintf($query, $_SERVER['username']); $result = mysql_query($fquery, $db); What will that do? ^ Quote Link to comment https://forums.phpfreaks.com/topic/171167-solved-i-cant-find-the-error-can-you/#findComment-902648 Share on other sites More sharing options...
seopaul Posted August 20, 2009 Share Posted August 20, 2009 i noticed this first of, but now you have posted the full script, its because your using elseif... change that to if($_POST['equip']){ and bobs your uncle as they say Quote Link to comment https://forums.phpfreaks.com/topic/171167-solved-i-cant-find-the-error-can-you/#findComment-902649 Share on other sites More sharing options...
Cetanu Posted August 20, 2009 Author Share Posted August 20, 2009 and bobs your uncle as they say >_> Sure..... Thanks! It's fixed. Quote Link to comment https://forums.phpfreaks.com/topic/171167-solved-i-cant-find-the-error-can-you/#findComment-902651 Share on other sites More sharing options...
ignace Posted August 20, 2009 Share Posted August 20, 2009 i noticed this first of, but now you have posted the full script, its because your using elseif... change that to if ($_POST['equip']){ and bobs your uncle as they say You mean if (!empty($_POST['equip'])) as if ($_POST['equip']) will throw an error like: 'equip' undefined index on line .. Quote Link to comment https://forums.phpfreaks.com/topic/171167-solved-i-cant-find-the-error-can-you/#findComment-902676 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.