Jump to content

[SOLVED] case; one working.


grlayouts

Recommended Posts

ok a have a php case where there is a drop down you select the feature and type the amount and it should run. but only my first case is working the weights one. any idea's?

 

                <?php
print "<form method=post action=intrain.php?view=train&step=trainingturns>Use<input name=amount>Energy Training On <select name=training><option value=weights>Weights</option><option value=agility>Tredmill</option></select>. <input type=submit value=Buy></form>";
if (isset($_POST)){
switch($_POST['training'])
{
	case "weights":
		if ($stat[energy] < $amount) {
print "<br>Your going to need $amount to train that hard.";
}
elseif ($stat[hp] < 1.0) {
print "<br>You cant train unless you are alive you loser.";
} else {
$chance = rand(1,10);
$chance13 = rand(1,2) / 700 / $stat[level] * $amount;
$chance14 = rand(3,5) / 700 / $stat[level] * $amount;
if ($chance == 1) {
print "<center>Man you were so bad in the gym<bR> you got kicked out for slacking<br>next time actually do some weights.";
mysql_query("update players set energy=energy-$amount where id=$stat[id]");
} else {
print " <center>Hey $stat[user] i never knew you were that fast!<br> you should come here more often if you want to stay in that condition<bR>You gained $chance14 strength<br>and $chance13 agility<br> <a href=intrain.php?action=tredmill>Run Again</a><bR><br> ";
mysql_query("update players set strength=strength+$chance14 where id=$stat[id]");
mysql_query("update players set agility=agility+$chance13 where id=$stat[id]");
mysql_query("update players set energy=energy-$amount where id=$stat[id]");
			}
			}
			}
}
break;
	case "agilty":
		if ($stat[energy] < $amount) {
print "<br>Your going to need $amount to train that hard.";
}
elseif ($stat[hp] < 1.0) {
print "<br>You cant train unless you are alive you loser.";
} else {
$chance = rand(1,10);
$chance13 = rand(1,2) / 700 / $stat[level] * $amount;
$chance14 = rand(3,5) / 700 / $stat[level] * $amount;
if ($chance == 1) {
print "<center>Man you were so bad in the gym<bR> you got kicked out for slacking<br>next time actually do some weights.";
mysql_query("update players set energy=energy-$amount where id=$stat[id]");
} else {
print " <center>Hey $stat[user] i never knew you were that fast!<br> you should come here more often if you want to stay in that condition<bR>You gained $chance14 strength<br>and $chance13 agility<br> <a href=intrain.php?action=tredmill>Run Again</a><bR><br> ";
mysql_query("update players set strength=strength+$chance13 where id=$stat[id]");
mysql_query("update players set agility=agility+$chance14 where id=$stat[id]");
mysql_query("update players set energy=energy-$amount where id=$stat[id]");
			}
			}
			}
}
?>

Link to comment
Share on other sites

Hello,

 

I too agree with thorpe for giving logical indentation though it is code of 20 lines or less. See because of 'not having logical indentation' in your code, you were not able to find the problem in your posted code. Here you were having two additional closings after case 'weights' . Check the modified code and see if you could have your problem solved.

 

<?php
print "<form method=post action=intrain.php?view=train&step=trainingturns>Use<input name=amount>Energy Training On <select name=training><option value=weights>Weights</option><option value=agility>Tredmill</option></select>. <input type=submit value=Buy></form>";
if (isset($_POST))
{
switch($_POST['training'])
{
	case "weights":
		if ($stat[energy] < $amount) 
		{
			print "<br>Your going to need $amount to train that hard.";
		}
		elseif ($stat[hp] < 1.0) 
		{
			print "<br>You cant train unless you are alive you loser.";
		} 
		else 
		{
			$chance = rand(1,10);
			$chance13 = rand(1,2) / 700 / $stat[level] * $amount;
			$chance14 = rand(3,5) / 700 / $stat[level] * $amount;
			if ($chance == 1) 
			{
				print "<center>Man you were so bad in the gym<bR> you got kicked out for slacking<br>next time actually do some weights.";
				mysql_query("update players set energy=energy-$amount where id=$stat[id]");
			} 
			else 
			{
				print " <center>Hey $stat[user] i never knew you were that fast!<br> you should come here more often if you want to stay in that condition<bR>You gained $chance14 strength<br>and $chance13 agility<br> <a href=intrain.php?action=tredmill>Run Again</a><bR><br> ";
				mysql_query("update players set strength=strength+$chance14 where id=$stat[id]");
				mysql_query("update players set agility=agility+$chance13 where id=$stat[id]");
				mysql_query("update players set energy=energy-$amount where id=$stat[id]");
			}
		}
//} ADDITIONAL CLOSING
//}ADDITIONAL CLOSING
	break;
	case "agilty":
		if ($stat[energy] < $amount) 
		{
			print "<br>Your going to need $amount to train that hard.";
		}
		elseif ($stat[hp] < 1.0) 
		{
			print "<br>You cant train unless you are alive you loser.";
		} 
		else 
		{
			$chance = rand(1,10);
			$chance13 = rand(1,2) / 700 / $stat[level] * $amount;
			$chance14 = rand(3,5) / 700 / $stat[level] * $amount;
			if ($chance == 1) 
			{
				print "<center>Man you were so bad in the gym<bR> you got kicked out for slacking<br>next time actually do some weights.";
				mysql_query("update players set energy=energy-$amount where id=$stat[id]");
			} 
			else 
			{
				print " <center>Hey $stat[user] i never knew you were that fast!<br> you should come here more often if you want to stay in that condition<bR>You gained $chance14 strength<br>and $chance13 agility<br> <a href=intrain.php?action=tredmill>Run Again</a><bR><br> ";
				mysql_query("update players set strength=strength+$chance13 where id=$stat[id]");
				mysql_query("update players set agility=agility+$chance14 where id=$stat[id]");
				mysql_query("update players set energy=energy-$amount where id=$stat[id]");
			}
		}

}
}
?>

Regards,

Link to comment
Share on other sites

Hello,

 

Again a small spelling mistake...

 

Print the $_POST variable inside if and see the output. You have spelled '[training] => agility' to '[training] => agilty'. Missing with 'i'.

 

Hope now you will get the required results.

 

Regards,

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.