Jump to content

Recommended Posts

Here's my whole code:

<?PHP
include('Connect.php');
include('top.php');
$ID= $_SESSION['UserID'];
$ID= mysql_real_escape_string($ID);
if(!isset($_SESSION['UserID']))
{
echo "Sorry, you must be logged in to view this page.";
include('bottom.php');
exit;
}
$Result1= mysql_query("SELECT * FROM users WHERE ID='$ID'");
$Rows1= mysql_fetch_array($Result1);
$Weapon= $Rows1['Weapon'];
$Weapon_Level= $Rows1['Weapon_Level'];
$Weapon_Type= $Rows1['Weapon_Type'];
$Weapon_Name= $Rows1['Weapon'];

if($Weapon_Level==1)
{
echo "Hello, this is the blacksmith. Here you may upgrade or downgrade your weapons. The weapon chosen is the one equipped.<br /><br />";
echo "Sorry, you can not downgrade or upgrade this weapon, because it is only level 1.";
}
if($Weapon_Level == 5)
{
if(isset($_POST['Submit4']))
{
$Result1= mysql_query("SELECT * FROM users WHERE ID='$ID'");
$Rows1= mysql_fetch_array($Result1);
$Weapon= $Rows1['Weapon'];
$Weapon_Level= $Rows1['Weapon_Level'];
$Weapon_Type= $Rows1['Weapon_Type'];
$Weapon_Name= $Rows1['Weapon'];
	if($Weapon_Name=="Windmill")
	{
	$FLR=35;
	}
	if($Weapon_Name=="Kunai");
	{
	$FLR=20;
	}
	if($Weapon_Name=="Steel Windmill")
	{
	$FLR=50;
	}
	if($Weapon_Name=="Steel Kunai");
	{
	$FLR=40;
	}
	if($Weapon_Name=="Silver Windmill")
	{
	$FLR=65;
	}
	if($Weapon_Name=="Silver Kunai");
	{
	$FLR=60;
	}
	if($Weapon_Name=="Golden Windmill")
	{
	$FLR=80;
	}
	if($Weapon_Name=="Golden Kunai");
	{
	$FLR=80;
	}
	$WL=1;
	$WEXP=0;
	if($Weapon_Type=="Regular")
	{
		$WNEXP=500;
		$WeaponType="Steel";
		$WeaponName="$WeaponType $Weapon_Name";
	}
	if($Weapon_Type=="Steel")
	{
		$WNEXP=5000;
		$WeaponType="Silver";
		$WeaponName="$WeaponType $Weapon_Name";
	}
	if($Weapon_Type=="Silver")
	{
		$WNEXP=50000;
		$WeaponType="Gold";
		$WeaponName="$WeaponType $Weapon_Name";
	}
	if($Weapon_Type=="Gold")
	{
		$WNEXP=9999999999999999;
		$WeaponType="Platinum";
		$WeaponName="$WeaponType $Weapon_Name";
	}
	$WNEXP= mysql_real_escape_string($WNEXP);
	$WL= mysql_real_escape_string($WL);
	$WEXP=mysql_real_escape_string($WEXP);
	$WeaponType= mysql_real_escape_string($WeaponType);
	$WeaponName= mysql_real_escape_string($WeaponName);
	$FLR= mysql_real_escape_string($FLR);
	$Wep_2="";
	$Wep_2=mysql_real_escape_string($wep_2);
	$WepT2="Weapon";
	$WepT2=mysql_real_escape_string($WepT2);
	mysql_query("UPDATE users SET Weapon_EXP='$WEXP', Weapon_NEXP='$WEXP', Weapon_Boost='$WEXP', Defense_Boost='$WEXP', Weapon_Level='$WEXP', Weapon='$Wep_2' WHERE ID='$ID'");
	mysql_query("INSERT into item_box (Item_NEXP, Item_Level, Item_Type, Item_Type2, Item_Name, Item_LevelR) VALUES('$WNEXP', '$WL', '$WepT2', '$WeaponType', '$WeaponName', '$FLR')");
	echo "Your weapon has been reduced to level one, and has been upgraded to a(n) $WeaponName. Go <a href='blacksmith.php'>back</a>";
}
else
{
if(isset($_POST['Submit3']))
{
	echo "Are you SURE you want to upgrade? You will lose all levels and EXP on the weapon, BUT, you will get a better weapon with a stronger base attack in return.<br /><br />";
$Result1= mysql_query("SELECT * FROM users WHERE ID='$ID'")or die(mysql_error());
$Rows1= mysql_fetch_array($Result1) or die(mysql_error());
$Weapon= $Rows1['Weapon'];
$Weapon_Level= $Rows1['Weapon_Level'];
$Weapon_Type= $Rows1['Weapon_Type'];
$Weapon_Name= $Rows1['Weapon'];
	if($Weapon_Name=="Windmill")
	{
	$FLR=35;
	}
	if($Weapon_Name=="Kunai");
	{
	$FLR=20;
	}
	if($Weapon_Name=="Steel Windmill")
	{
	$FLR=50;
	}
	if($Weapon_Name=="Steel Kunai");
	{
	$FLR=40;
	}
	if($Weapon_Name=="Silver Windmill")
	{
	$FLR=65;
	}
	if($Weapon_Name=="Silver Kunai");
	{
	$FLR=60;
	}
	if($Weapon_Name=="Golden Windmill")
	{
	$FLR=80;
	}
	if($Weapon_Name=="Golden Kunai");
	{
	$FLR=80;
	}
	echo "$Weapon_Name $FLR";
	echo "NOTE: The weapon will go into your inventory after upgrading. Your upgraded weapon's required level is: $FLR";
	echo "<br /><form method='post'><input type='submit' name='Submit4' value='Yes'></form>";
}
else
{
echo "Hello, this is the blacksmith. Here you may upgrade or downgrade your weapons. The weapon chosen is the one equipped.<br /><br />";	
	echo "You may upgrade this weapon. If you upgrade this weapon, you'll lose all EXP and levels on the weapon. It will go up one weapon state. The orders are: Regular, Steel, Silver, Gold, Platinum. Platinums can not level, but have a big base attack boost. For every upgrade, you will get a base attack boost. Do you wish to upgrade it?";
	echo "<br /><form method='post'><input type='submit' name='Submit3' value='Upgrade'></form>";
}
}	
}
if($Weapon_Level > 1 && $Weapon_Level < 5)
{
if(isset($_POST['Submit2']))
{
	$WL=1;
	$WEXP=0;
	if($Weapon_Type=="Regular")
	{
		$WNEXP=50;
	}
	if($Weapon_Type=="Steel")
	{
		$WNEXP=500;
	}
	if($Weapon_Type=="Silver")
	{
		$WNEXP=5000;
	}
	if($Weapon_Type=="Gold")
	{
		$WNEXP=50000;
	}
	$WNEXP= mysql_real_escape_string($WNEXP);
	$WL= mysql_real_escape_string($WL);
	$WEXP=mysql_real_escape_string($WEXP);
	mysql_query("UPDATE users SET Weapon_EXP='$WEXP', Weapon_NEXP='$WNEXP', Weapon_Boost='$WEXP', Defense_Boost='$WEXP', Weapon_Level='$WL' WHERE ID='$ID'");
	echo "Your weapon has been reduced to level one. Go <a href='blacksmith.php'>back</a>";
}
else
{
if(isset($_POST['Submit1']))
{
	echo "Are you SURE you want to downgrade? You will lose all levels and EXP on the weapon.";
	echo "<br /><form method='post'><input type='submit' name='Submit2' value='Yes'></form>";
}
else
{
echo "Hello, this is the blacksmith. Here you may upgrade or downgrade your weapons. The weapon chosen is the one equipped.<br /><br />";	
	echo "You may downgrade this weapon. If you downgrade this weapon, you'll lose all EXP and levels on the weapon. It will <b>not</b> lose it's weapon state (Steel, Silver, Gold, Diamond) if it has one. You can ONLY trade/sell a weapon if it is level 1. Do you wish to downgrade it?";
	echo "<br /><form method='post'><input type='submit' name='Submit1' value='Downgrade'></form>";
}
}
}
include('bottom.php');
?>

 

Here's where you should be looking at:

 

		if($Weapon_Name=="Windmill")
	{
	$FLR=35;
	}
	if($Weapon_Name=="Kunai");
	{
	$FLR=20;
	}
	if($Weapon_Name=="Steel Windmill")
	{
	$FLR=50;
	}
	if($Weapon_Name=="Steel Kunai");
	{
	$FLR=40;
	}
	if($Weapon_Name=="Silver Windmill")
	{
	$FLR=65;
	}
	if($Weapon_Name=="Silver Kunai");
	{
	$FLR=60;
	}
	if($Weapon_Name=="Golden Windmill")
	{
	$FLR=80;
	}
	if($Weapon_Name=="Golden Kunai");
	{
	$FLR=80;
	}
	echo "$Weapon_Name $FLR";

 

Now this is weird. It echos it as "Kunai 80" when clearly they dont fall under the same if.

How it did that, I have no clue.

 

Help, please. If you're wondering why it's all ifs, it's because I get "Unexpected ELSEIF" if they arent"

Link to comment
https://forums.phpfreaks.com/topic/166932-solved-very-weird-php-problem/
Share on other sites

Why not use switch statements instead of if blocks?

 


   switch ($Weapon_Name)
   {
      case "Windmill":
         $FLR = 35;
      break;
      
      case "Kunai":
         $FLR = 20;
      break;
      
      //ETC...
      default:
         $FLR = 0;
   }

Help, please. If you're wondering why it's all ifs, it's because I get "Unexpected ELSEIF" if they arent"

 

How about a switch ten? ;)

 

$WNEXP=9999999999999999;

 

Can't be used as it exceeds the integer (and possibly float) which means you'll get a negative number for $WNEXP. Use PHP_INT_MAX instead or keep this information db-based.

No, it was just a noob mistake, lol, no errors anymore.

 

@mmarif: It's funny because I can code very well and don't hit too many errors, but once in a while I pull a noob xD

 

$ID= $_SESSION['UserID'];
$ID= mysql_real_escape_string($ID);
if(!isset($_SESSION['UserID']))
{
   echo "Sorry, you must be logged in to view this page.";
   include('bottom.php');
   exit;
}

 

should be:

if(!isset($_SESSION['UserID']))
{
   echo "Sorry, you must be logged in to view this page.";
   include('bottom.php');
   exit;
}

$ID= $_SESSION['UserID'];
$ID= mysql_real_escape_string($ID);

 

Because if !isset($_SESSION['UserID']) then $ID= $_SESSION['UserID']; throws an e_notice: undefined index UserID

 

Use mysql_fetch_assoc() instead of mysql_fetch_array() as it gives you both a numerical as an associative array back or atleast use MYSQL_NUM or MYSQL_ASSOC as a second optional parameter.

 

Also you pull this information 3 times: $Result1= mysql_query("SELECT * FROM users WHERE ID='$ID'"); While $Result1 still holds the information you need and instead of re-using this information you query the db instead.

 

$WNEXP=9999999999999999;

 

Can't be used as it exceeds the integer (and possibly float) which means you'll get a negative number for $WNEXP. Use PHP_INT_MAX instead or keep this information db-based.

 

if($Username=="Xyphon")

{

$You="Awesome!";

}

 

Not yet ;)

$ID= $_SESSION['UserID'];
$ID= mysql_real_escape_string($ID);
if(!isset($_SESSION['UserID']))
{
   echo "Sorry, you must be logged in to view this page.";
   include('bottom.php');
   exit;
}

 

Works fine, I've never gotten an error. I don't see why it wouldnt, not like it's saying (if(!isset($ID)) which would probably bring an error.

 

Use mysql_fetch_assoc() instead of mysql_fetch_array() as it gives you both a numerical as an associative array back or atleast use MYSQL_NUM or MYSQL_ASSOC as a second optional parameter.

It doesn't matter for the reasons I use it, I only need fetch_array currently.

 

Also you pull this information 3 times: $Result1= mysql_query("SELECT * FROM users WHERE ID='$ID'"); While $Result1 still holds the information you need and instead of re-using this information you query the db instead.

Yeah, I thought that may have been the reason for the error, and I never got around to editing it out before posting it here.

 

Also, although 999999999999 is over the max, it just converts it into the max, because I tested it and in the database it says:

2147483647

 

 

So yes, the statement in my signature is still true.

 

 

Works fine, I've never gotten an error. I don't see why it wouldnt, not like it's saying (if(!isset($ID)) which would probably bring an error.

 

error_reporting(E_ALL);

ini_set('display_errors', TRUE);

 

And go to the page as not logged in and you'd get something like: Notice: undefined index 'UserID'. You should always program in a logic manner not first use a variable and afterwards question if it actually even exists?

 

Use mysql_fetch_assoc() instead of mysql_fetch_array() as it gives you both a numerical as an associative array back or atleast use MYSQL_NUM or MYSQL_ASSOC as a second optional parameter.

It doesn't matter for the reasons I use it, I only need fetch_array currently.

 

You use the double of memory then is actually required in a small application this may not be a problem however in bigger applications you may consume just that too much memory.

 

Also you pull this information 3 times: $Result1= mysql_query("SELECT * FROM users WHERE ID='$ID'"); While $Result1 still holds the information you need and instead of re-using this information you query the db instead.

Yeah, I thought that may have been the reason for the error, and I never got around to editing it out before posting it here.

 

Also, although 999999999999 is over the max, it just converts it into the max, because I tested it and in the database it says:

2147483647

 

Because PHP chopped it for you to it's maximum integer size (PHP_INT_MAX). In my opinion it's bad practice and if you'll ever work in a bank let me know so I don't deposit there ;) Besides you are creating a game type which is known for his million users with their billion dollar accounts, they may get disappointed when it suddenly drops from 16 billion to 2 billion ;) Have you tought about that?

 

So yes, the statement in my signature is still true.

 

I didn't wanted to offend you and it surely shows that you are ambigious about what you do, however modesty is much more appreciated ;) I can say that I'm the #1 programmer however some may disagree (and some will call me a liar, which I probably am :D) ;) HAHA

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.