And I'm just having problems getting to the function apparently. I've tried multiple different things from what I have looked up, but it is just not getting into the function. I've tested by just a simple echo that should display after it is submitted, but it never gets to it. The function is on the same page as the form
The code for the form, and for what should happen when it is submitted is below.
I learned a good bit of PHP, but been out of practice for a while due to school. I've also been learning C++ and Java, so I think some of it is kind of melting together.
- Code: Select all
if (isset($_POST['trainUnits'])){
while($units = mysql_fetch_array($resultUnits)){
$queryBuy="UPDATE army SET units[name]=units[name] + " . $_POST[unit] . "WHERE id=$_SESSION[user_id]";
mysql_query($queryBuy)or die(mysql_error("*Query failed. Units were not purchased."));
}
//after making purchase, get users UPDATED army
$queryArmy="SELECT * FROM army WHERE id=$_SESSION[user_id]";
$resultArmy=mysql_query($queryArmy);
$army=mysql_fetch_array($resultArmy);
echo 'You successfully purchased your units.';
}
- Code: Select all
echo '<tr><td>Unit:</td><td>You have:</td><td>Cost</td><td>Upkeep(food)</td><td>Quantity:</td>';
echo '<form action="" method="post">';
while($units = mysql_fetch_array($resultUnits)){
echo '<tr><td>' . ucfirst($units[name]) . '</td><td>' . $army[$units[name]] . '</td><td>' . $units[cost] . '</td><td>' . $units[food] . '</td><td><input type="text" size="3" name=" . $units[name] . "></td></tr>';
}
echo '</tr>';
echo '<tr><td> </td><td> </td><td> </td><td> </td><td>';
echo '<input type="submit" value="Train" id="trainUnits" name="trainUnits">';
echo '</form>';
Thanks!
