LOUDMOUTH Posted March 15, 2009 Share Posted March 15, 2009 Can you add an option value to this? <center><input type='text' name='energy' value='<?php echo $user_class->energy ?>' size='5' maxlength='5'> <input class="button" type="submit" name="train" value="Train Strength" /> <input class="button" type="submit" name="train" value="Train Defense" /> <input class="button" type="submit" name="train" value="Train Speed" /><br /><br /> this was what it was before and I want to use 3 submit buttons instead of a drop down form. <input type='text' name='energy' value='<?php echo $user_class->energy ?>' size='5' maxlength='5'> <select name='type'> <option value='1'>Strength</option> <option value='2'>Defense</option> <option value='3'>Speed</option> </select> <input type='submit' name='train' value='Train'><br> </form> Quote Link to comment https://forums.phpfreaks.com/topic/149502-solved-option-values/ Share on other sites More sharing options...
LOUDMOUTH Posted March 15, 2009 Author Share Posted March 15, 2009 anyone that can help me out? Quote Link to comment https://forums.phpfreaks.com/topic/149502-solved-option-values/#findComment-785483 Share on other sites More sharing options...
Andy-H Posted March 15, 2009 Share Posted March 15, 2009 Yes, <input type='text' name='energy' value='<?php echo $user_class->energy ?>' size='5' maxlength='5' /> <input class="button" type="submit" name="train" value="Train Strength" /><br /> <input class="button" type="submit" name="train" value="Train Defense" /><br /> <input class="button" type="submit" name="train" value="Train Speed" /> And then process the postdata like so: $type = $_POST['train']; if ($type == 'Train Strength') { // Code to train strength! } elseif ($type == 'Train Defense') { // Code to train defense! } elseif ($type == 'Train Speed') { // Code to train speed! } else { echo 'Input invalid!'; } Although a select box is probably better looking... Quote Link to comment https://forums.phpfreaks.com/topic/149502-solved-option-values/#findComment-785486 Share on other sites More sharing options...
LOUDMOUTH Posted March 15, 2009 Author Share Posted March 15, 2009 This is what I have now and it's not working if ($_POST['train'] != "") { $_POST['energy'] = abs((int) $_POST['energy']); if ($_POST['energy'] > $user_class->energy){ echo Message("You don't have that much energy."); include "footer.php"; die(); } if ($_POST['energy'] < 1){ echo Message("Please enter a valid amount."); include "footer.php"; die(); } if($_POST['type'] == Train Strength){ // strength $newstrength = $user_class->strength + floor($_POST['energy'] * ($user_class->awake / 100)); $newtotal = floor($_POST['energy'] * ($user_class->awake / 100)); $result = mysql_query("UPDATE `grpgusers` SET `total` = total+$newtotal, `strength` = '".$newstrength."' WHERE `id` = '".$user_class->id."'"); echo Message("You trained with ".$_POST['energy']." energy and recieved ".floor($_POST['energy'] * ($user_class->awake / 100))." strength."); }elseif($_POST['type'] == Train Defense){ // defense $newdefense = $user_class->defense + floor($_POST['energy'] * ($user_class->awake / 100)); $newtotal = floor($_POST['energy'] * ($user_class->awake / 100)); $result = mysql_query("UPDATE `grpgusers` SET `total` = total+$newtotal, `defense` = '".$newdefense."' WHERE `id` = '".$user_class->id."'"); echo Message("You trained with ".$_POST['energy']." energy and recieved ".floor($_POST['energy'] * ($user_class->awake / 100))." defense."); }elseif($_POST['type'] == Train Speed){ // speed $newspeed = $user_class->speed + floor($_POST['energy'] * ($user_class->awake / 100)); $newtotal = floor($_POST['energy'] * ($user_class->awake / 100)); $result = mysql_query("UPDATE `grpgusers` SET `total` = total+$newtotal, `speed` = '".$newspeed."' WHERE `id` = '".$user_class->id."'"); echo Message("You trained with ".$_POST['energy']." energy and recieved ".floor($_POST['energy'] * ($user_class->awake / 100))." speed."); } $newawake = $user_class->awake - (2 * $_POST['energy']); if ($newawake <0 ){ $newawake = 0; } $newenergy = $user_class->energy - $_POST['energy']; $result = mysql_query("UPDATE `grpgusers` SET `awake` = '".$newawake."', `energy` = '".$newenergy."' WHERE `id` = '".$user_class->id."'"); $user_class = new User($_SESSION['id']); } ?> <tr><td class="contenthead">Gym</td></tr> <form method='post'> <tr><td class="contentcontent"> You can currently train <?php echo $user_class->energy; ?> times.</td></tr> <tr><td class="contentcontent"><br /> <center><input type='text' name='energy' value='<?php echo $user_class->energy ?>' size='5' maxlength='5' /> <input class="button" type="submit" name="train" value="Train Strength" /> <input class="button" type="submit" name="train" value="Train Defense" /> <input class="button" type="submit" name="train" value="Train Speed" /><br /><br /><a href="/spendpoints.php?spend=energy">Refill energy</a> Careful: It will refill energy without confirmation.</center><br /></td> Quote Link to comment https://forums.phpfreaks.com/topic/149502-solved-option-values/#findComment-785496 Share on other sites More sharing options...
Andy-H Posted March 16, 2009 Share Posted March 16, 2009 if (isSet($_POST['train'])) { $energy= (int)abs($_POST['energy']); if ($energy > $user_class->energy){ echo Message("You don't have that much energy."); include "footer.php"; die(); } if ($energy < 1){ echo Message("Please enter a valid amount."); include "footer.php"; die(); } if($_POST['train'] == 'Train Strength'){ // strength $newstrength = $user_class->strength + floor($energy * ($user_class->awake / 100)); $newtotal = floor($energy * ($user_class->awake / 100)); $result = mysql_query("UPDATE `grpgusers` SET `total` = total+$newtotal, `strength` = '".$newstrength."' WHERE `id` = '".$user_class->id."'"); echo Message("You trained with ".$energy." energy and recieved ".floor($energy * ($user_class->awake / 100))." strength."); }elseif($_POST['train'] == 'Train Defense'){ // defense $newdefense = $user_class->defense + floor($energy * ($user_class->awake / 100)); $newtotal = floor($energy * ($user_class->awake / 100)); $result = mysql_query("UPDATE `grpgusers` SET `total` = total+$newtotal, `defense` = '".$newdefense."' WHERE `id` = '".$user_class->id."'"); echo Message("You trained with ".$energy." energy and recieved ".floor($energy * ($user_class->awake / 100))." defense."); }elseif($_POST['train'] == 'Train Speed'){ // speed $newspeed = $user_class->speed + floor($energy * ($user_class->awake / 100)); $newtotal = floor($energy * ($user_class->awake / 100)); $result = mysql_query("UPDATE `grpgusers` SET `total` = total+$newtotal, `speed` = '".$newspeed."' WHERE `id` = '".$user_class->id."'"); echo Message("You trained with ".$energy." energy and recieved ".floor($energy * ($user_class->awake / 100))." speed."); } $newawake = $user_class->awake - (2 * $energy); if ($newawake <0 ){ $newawake = 0; } $newenergy = $user_class->energy - $energy; $result = mysql_query("UPDATE `grpgusers` SET `awake` = '".$newawake."', `energy` = '".$newenergy."' WHERE `id` = '".$user_class->id."'"); $user_class = new User($_SESSION['id']); } ?> <tr><td class="contenthead">Gym</td></tr> <form method='post'> <tr><td class="contentcontent"> You can currently train <?php echo $user_class->energy; ?> times.</td></tr> <tr><td class="contentcontent"><br /> <center><input type='text' name='energy' value='<?php echo $user_class->energy ?>' size='5' maxlength='5' /> <input class="button" type="submit" name="train" value="Train Strength" /> <input class="button" type="submit" name="train" value="Train Defense" /> <input class="button" type="submit" name="train" value="Train Speed" /><br /><br /><a href="/spendpoints.php?spend=energy">Refill energy</a> Careful: It will refill energy without confirmation.</center><br /></td> Quote Link to comment https://forums.phpfreaks.com/topic/149502-solved-option-values/#findComment-785513 Share on other sites More sharing options...
LOUDMOUTH Posted March 16, 2009 Author Share Posted March 16, 2009 Thank you soo much! Works like a dream! Quote Link to comment https://forums.phpfreaks.com/topic/149502-solved-option-values/#findComment-785584 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.