I've been lurking and learning and developing this stuff, but I can't seem to figure out a few things with this stuff.
I am trying to make a simple webgame. There are 3 units and 2 resources. The units are Recruits, Chefs, and Miners. The resources are food and ore. Every 5 minutes each Chef produces 1 food, and each Miner produces 1 ore. A recruit may be purchased for 5 food, and a recruit can be turned into a Chef or a Miner.
I'm going to post my code first, then ask my questions
member.php
<?php
session_start();
if($_SESSION['s_logged_n'] == 'true'){
include 'process.php';
include 'config.php';
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Welcome to Kombat Kingdom!</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
<div id="head">Kombat Kingdom</div><br>
<div id="container">
<?php
include 'menus.php'
?>
</div>
<div id="spacer"> </div>
<div id="memmain">
<?php
$username = $_SESSION['s_username'];
$miners = mysql_query("
SELECT miners
FROM Users
WHERE Username='$username'
LIMIT 1");
$chefs = mysql_query("SELECT chefs FROM Users
WHERE Username='$username'");
$ore = mysql_query("SELECT ore FROM Users
WHERE Username='$username'");
$food = mysql_query("SELECT food FROM Users
WHERE Username='$username'");
$recruits = mysql_query("SELECT recruits FROM Users
WHERE Username='$username'");
echo '<p> Welcome to Nerdworks, this is the beta for Kombat Kingdom! It is still a work in progress, so if something does not work it will either be working soon or we has no clue it is broken! Please contact admin@nerdworks.info if anything is malfunctioning <br>Thanks,<br> Frodo</p>';
switch($_GET['change']){
case 'Hire+Chef':
{
if($recruits > 0)
{
$recruits = $recruits - 1;
$chefs=$chefs+1;
mysql_query ("UPDATE Users
SET chefs = '$chefs'
WHERE id='$id'");
mysql_query ("CREATE EVENT $chefs ON SCHEDULE EVERY 5 MINUTES DO
$food = $food+1;
UPDATE Users SET food = '$food'
WHERE id='$id'");
echo '<p>You have successfully hired 1 chef.</p>';
}
else
{
echo '<p>Sorry, you need atleast one recruit!</p>';
}
break;
}
case 'Hire+Miner':
{
if($recruits > 0)
{
$recruits = $recruits - 1;
$chefs=$chefs+1;
mysql_query ("UPDATE Users
SET chefs = '$chefs'
WHERE id='$id'");
mysql_query ("CREATE EVENT $chefs ON SCHEDULE EVERY 5 MINUTES DO
$food = $food+1;
UPDATE Users SET food = '$food'
WHERE id='$id'");
echo '<p>You have successfully hired 1 miner.</p>';
}
else
{
echo '<p>Sorry, you need atleast one recruit!</p>';
}
break;
}
case 'Hire+Recruit':
{
if($recruits > 0)
{
$recruits = $recruits - 1;
$chefs=$chefs+1;
mysql_query ("UPDATE Users
SET chefs = '$chefs'
WHERE id='$id'");
mysql_query ("CREATE EVENT $chefs ON SCHEDULE EVERY 5 MINUTES DO
$food = $food+1;
UPDATE Users SET food = '$food'
WHERE id='$id'");
echo '<p>You have successfully hired 1 recruit.</p>';
}
else
{
echo '<p>Sorry, you need atleast one recruit!</p>';
}
break;
}
case 'password':
{
echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<p>Current password:<br>
<input name="current" type="password" class="textBox"></p>
<p>New password:<br>
<input name="new" type="password" class="textBox"></p>
<p>Confirm new password:<br>
<input name="confirm" type="password" class="textBox"></p>
<p><input type="submit" value="Change Password" name="changepassword"></p>
</form>
';
break;
}
case 'email':
{
echo '<p>
WARNING! - By changing your email address you will have to re-validate. Make sure you email address is 100% correct.</p>
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<p>Current email:<br>
<input name="current" type="text" class="textBox"></p>
<p>New email:<br>
<input name="new" type="text" class="textBox"></p>
<p>Confirm new email:<br>
<input name="confirm" type="text" class="textBox"></p>
<p><input type="submit" value="Change Email" name="changeemail"></p>
</form>
';
break;
}
case 'account':
{
echo '<p>
WARNING - By closing your account, you will not be able to login again under this account. Press the button below to confirm you wish to close your account</p>
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<p><input type="submit" value="Close Account" name="closeaccount"></p>
</form>
';
break;
}
case 'play':
{
echo '<p>You have ';
echo $miners;
echo ' miners
<img src="miner.gif">
<form>
<input type = "submit" value = "Hire Miner" name = "change" action="member.php" method="post" ></p>
</form>';
echo '<p>You have ';
echo $chefs;
echo ' chefs
<img src="chef.gif">
<form>
<input type = "submit" value = "Hire Chef" name = "change" action="member.php" method="post" ></p>
</form>';
echo '<p>You have ';
echo $recruits;
echo ' recruits';
echo ' <img src="recruit.gif">
<form>
<input type = "submit" value = "Hire Recruit" name = "change" action="member.php" method="post" ></p>
</form>';
echo'<p><img src="food.bmp">';
echo $food;
echo '<p><img src="ore.bmp">';
echo $ore;
break;
}
default:
{
}
}}
?>
</div>
</body>
</html>
menus.php
<?php session_start();
if($_GET['set'] > 0)
{
if($_SESSION['whattoclose'] == NULL)
{
$_SESSION['whattoclose'] = $_GET['set'];
} else {
$_SESSION['whattoclose'] = $_SESSION['whattoclose'] . '|' . $_GET['set'];
}
}
if($_GET['undo'] > 0)
{
if(!empty($_SESSION['whattoclose'])){
$_SESSION['whattoclose'] = str_replace("|".$_GET['undo'] , "" , $_SESSION['whattoclose']);
$_SESSION['whattoclose'] = str_replace($_GET['undo'] , "" , $_SESSION['whattoclose']);
}
}
function showTitle($id)
{
$title = array(
"Navigation",
"Login information",
);
$data = $_SESSION['whattoclose'];
$not = explode( "|" , $data );
if(!in_array( $id , $not ))
{
echo '<a href="member.php?set='.$id.'">close</a> - ';
echo $title[$id-1];
} else {
echo '<a href="member.php?undo='.$id.'">open</a> - ';
echo $title[$id-1];
}
}
function checkIt($id)
{
$data = array(
'<p><a href="logout.php">Logout</a></p>
<p><a href="member.php?change=password">Change Password</a></p>
<p><a href="member.php?change=email">Change Email</a></p>
<p><a href="member.php?change=account">Close account</a></p>
<p><a href="member.php?change=play">Click here to play!</a></p>
<p>Welcome to the members only page '.$_SESSION['s_name'].'!</p>
<p>You are logged in as '.$_SESSION['s_username'].' from the IP address '.$_SERVER['REMOTE_ADDR'].'</p>',
);
$str = $_SESSION['whattoclose'];
$not = explode( "|" , $str );
if(!in_array( $id , $not ))
{
echo '<div class="table">';
echo $data[$id-1];
echo '</div>';
}
}
?>
<div class="header">
<? showTitle(1) ?>
</div>
<? checkIt(1) ?>
<br>
<div class="header">
<? showTitle(2) ?>
</div>
<? checkIt(2) ?>
So those are the major portions of the code. If theres any other parts you need please let me know so I can post them!
So here are my problems, if anyone can help with one or two of them please post, even if you can't help with ALL of them.
1. When I load up members.php, it is supposed to display the variables from the MySql database, but instead it displays some jargon about "Resource id" instead of the values. I think it is because they aren't declaring properly, even though I declared them here:
$username = $_SESSION['s_username'];
$miners = mysql_query("
SELECT miners
FROM Users
WHERE Username='$username'
LIMIT 1");
$chefs = mysql_query("SELECT chefs FROM Users
WHERE Username='$username'");
$ore = mysql_query("SELECT ore FROM Users
WHERE Username='$username'");
$food = mysql_query("SELECT food FROM Users
WHERE Username='$username'");
$recruits = mysql_query("SELECT recruits FROM Users
WHERE Username='$username'");
Other problem, when I click one of the unit hiring buttons, it leads me back to the post URL like it should, but it doesn't display the Successful message, and it isn't updating the value when I view the Sql database, leading me to believe it isnt triggering the case in the switch at all.
Please, PLEASE help me! I will love you forever if you help me! Thankyou!
~Frodo of nerdworks.info

New Topic/Question
Reply




MultiQuote





|