Jump to content

[SOLVED] Option Values


LOUDMOUTH

Recommended Posts

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>

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>

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.