I have:
stuff (player stats):
id
user_name
nickname
level
cash
energy
xp
jobs (job stats):
id
job_name
level
cash
energy
xp
What I want to do is when they click the radio and click submit, the database would add the job stats to the players stats.
I am pretty sure this is totally wrong, but at least it shows the page with the form and not a blank screen. lol
Code: Select all
<?php
session_start();
if (array_key_exists("user", $_SESSION)) {
echo "Hello " . $_SESSION["user"];
}
else {
header('Location: index.php');
exit;
}
?>
<html>
<head></head>
<body>
<table border="black">
<tr>
<th>User Name</th>
<th>Nickname</th>
<th>Level</th>
<th>Cash</th>
<th>Energy</th>
<th>XP</th>
</tr>
<?php
require_once("Includes/db.php");
$playerID = getajobDB::getInstance()->get_player_id_by_name(mysql_real_escape_string($_SESSION["user"]));
$result = getajobDB::getInstance()->get_player_by_players_id($playerID);
while($row = mysql_fetch_array($result)) {
strip_tags($row["user_name"],'<br><p><h1>');
echo "<tr><td>" . $row["user_name"]."</td>";
strip_tags($row["nickname"],'<br><p><h1>');
echo "<td>".$row["nickname"]."</td>";
strip_tags($row["my_level"],'<br><p><h1>');
echo "<td>".$row["my_level"]."</td>";
strip_tags($row["cash"],'<br><p><h1>');
echo "<td>".$row["cash"]."</td>";
strip_tags($row["energy"],'<br><p><h1>');
echo "<td>".$row["energy"]."</td>";
strip_tags($row["xp"],'<br><p><h1>');
echo "<td>".$row["xp"]."</td>";
echo "</tr>\n";
}
//the top part to here works great.
?>
</table>
<br><br>
<?php
//the problem child.
if (!isset($_POST['jobs'])) {
echo "You need select a job. Get to work you hippie!";
} else {
foreach ($_POST['jobs'] as $selected_job) {
mysql_query("UPDATE stuff,jobs SET stuff.cash=stuff.cash+jobs.cash , stuff.energy=stuff.energy-jobs.energy, stuff.xp=stuff.xp+jobs.xp WHERE jobs.id='".$_POST["jobs"]."' AND stuff.id=$playerid");
echo "You have done ".$selected_job."!<br>";
}
}
?>
<form name="Jobs" method="post" action="dothejob.php">
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input type="radio" name="jobs[]" value="1"></td>
<td>Babysitting</td>
</tr>
<tr>
<td><input type="radio" name="jobs[]" value="2"></td>
<td>Mow the lawn</td>
</tr>
<tr>
<td><input type="radio" name="jobs[]" value="4"></td>
<td>Take out the trash</td>
</tr>
<tr>
<td><input type="radio" name="jobs[]" value="3"></td>
<td>Drive mom to work</td>
</tr>
</table>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>I am running the latest Apache, PHP, and MySQL, and using the NetBeans IDE, on dare I say? A windows XP box.
Thanks in advance for any advise given, I look at it as a good learning tool. I have been reading stuff all over the place over the last week this is fun.