grlayouts Posted October 1, 2007 Share Posted October 1, 2007 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]"); } } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/71336-solved-case-one-working/ Share on other sites More sharing options...
trq Posted October 1, 2007 Share Posted October 1, 2007 Sorry, but without any logical indentation your code is pretty well unreadable. Quote Link to comment https://forums.phpfreaks.com/topic/71336-solved-case-one-working/#findComment-358934 Share on other sites More sharing options...
grlayouts Posted October 1, 2007 Author Share Posted October 1, 2007 indentation. the script is about 20 lines long and i wouldnt say complex Quote Link to comment https://forums.phpfreaks.com/topic/71336-solved-case-one-working/#findComment-358939 Share on other sites More sharing options...
hemlata Posted October 1, 2007 Share Posted October 1, 2007 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, Quote Link to comment https://forums.phpfreaks.com/topic/71336-solved-case-one-working/#findComment-358952 Share on other sites More sharing options...
grlayouts Posted October 1, 2007 Author Share Posted October 1, 2007 unfortunatly not. it now completes but nothing prints or updates in the database. Quote Link to comment https://forums.phpfreaks.com/topic/71336-solved-case-one-working/#findComment-358960 Share on other sites More sharing options...
hemlata Posted October 1, 2007 Share Posted October 1, 2007 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, Quote Link to comment https://forums.phpfreaks.com/topic/71336-solved-case-one-working/#findComment-358970 Share on other sites More sharing options...
grlayouts Posted October 1, 2007 Author Share Posted October 1, 2007 one missing i. lol thanks very much. Quote Link to comment https://forums.phpfreaks.com/topic/71336-solved-case-one-working/#findComment-358974 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.