PHP variable not 'sticking'
by redd9 from LinuxQuestions.org on (#532RD)
Hi everyone, I am trying to create a mana calculator for an RPG. The user enters the mana cost of a spell and it gets deducted from the user's total mana.
The program is working, except it only works once. Subsequent numbers enter do not subtract from the new mana but from the old one.
I have tried re-arranging things and changing the variables, and using an if statement instead of a while loop, but nothing seems to fix this. Any help would be appreciated.
Relevant code below:
PHP Code:<label for="mana_cost">Enter the spells mana cost: </label>
<input type="number" id="mana_cost" name="mana_cost" min="0" max="20" value="<?php echo $_POST['mana_cost']; ?>">
<label for="spells">Select a spell:</label>
<select id="spells">
<option value="accelerate_disease">Accelerate Disease - Advanced [5]</option>
<option value="adrenaline">Adrenaline - Advanced [7]</option>
<option value="alarm">Alarm - Novice [4]</option>
<option value="animate_lesser_zombie">Animate Lesser Zombie: - Novice [6]</option>
</select>
<input type="submit" value="Submit">PHP Code:$mana_cost = $_POST['mana_cost'];
$base_mana = $wisdom * 2;
$mana_remaining = $base_mana;
$mana = $base_mana;
while ($mana_cost !== 0) {
$mana_remaining = $mana - $mana_cost;
$mana = $mana_remaining;
$mana_cost = 0;
}


The program is working, except it only works once. Subsequent numbers enter do not subtract from the new mana but from the old one.
I have tried re-arranging things and changing the variables, and using an if statement instead of a while loop, but nothing seems to fix this. Any help would be appreciated.
Relevant code below:
PHP Code:<label for="mana_cost">Enter the spells mana cost: </label>
<input type="number" id="mana_cost" name="mana_cost" min="0" max="20" value="<?php echo $_POST['mana_cost']; ?>">
<label for="spells">Select a spell:</label>
<select id="spells">
<option value="accelerate_disease">Accelerate Disease - Advanced [5]</option>
<option value="adrenaline">Adrenaline - Advanced [7]</option>
<option value="alarm">Alarm - Novice [4]</option>
<option value="animate_lesser_zombie">Animate Lesser Zombie: - Novice [6]</option>
</select>
<input type="submit" value="Submit">PHP Code:$mana_cost = $_POST['mana_cost'];
$base_mana = $wisdom * 2;
$mana_remaining = $base_mana;
$mana = $base_mana;
while ($mana_cost !== 0) {
$mana_remaining = $mana - $mana_cost;
$mana = $mana_remaining;
$mana_cost = 0;
}