Jump to content

[SOLVED] I Can't Find the Error, CAN YOU?!


Cetanu

Recommended Posts

<?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.

Link to comment
Share on other sites

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']}'");

}
}
}
?>

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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? ^

Link to comment
Share on other sites

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 ..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.