I'm working on a MMOG, just for fun.
Now I need to get some data form MySQL, the resources for the 'villages'(in the game)
I think I have found the problem.
This is what I want the code to do:
*Get data from MySQL(checkstatus.php)
*Store it in a Session(checkstatus.php)
*Print it out(main.php)
The codes:
checkstatus.php
Code: Select all
<?php
// Server 1, checklogin.php
Session_start();
include "connect.config.php";
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select Database");
$data = mysql_query("SELECT * FROM `resoreces`")
or die(mysql_error());
Print "<table border cellpadding=3>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print "<th>Username:</th> <td>".$info['username'] . "</td>";
Print "</tr><tr>";
Print "<th>Gold:</th> <td>".$info['gold'] . "</td>"; // Forget this, just something I tested
Print "</tr><tr>";
Print "<th>Three:</th> <td>".$info['three'] . "</td> ";
Print "</tr><tr>";
Print "<th>Clay:</th> <td>".$info['clay'] . "</td> ";
Print "</tr><tr>";
Print "<th>Iron:</th> <td>".$info['iron'] . "</td> ";
Print "</tr><tr>";
Print "<th>Wheat:</th> <td>".$info['wheat'] . " </td>";
Print "</tr>"; // Now the session thing happends...
$_SESSION['Three'] = $info['three']; //<- Problem ( I think )
}
?>
<html>
<body>
<a href="main.php">Back</a>
</body>
</html>
<?php
Print "</table>";
?>
Code: Select all
<?php
// Server 1, main.php
Session_start();
if($_SESSION['LoginS1'] == false)
{
?>
<html>
<head>
<title>Access denied!</title>
</head>
<body>
<center>Access denied!</center>
<p>
Please login to view this site!
<p>
<a href="/Game/login.php">Login</a>
</body>
</html>
<?php
}
else
{
?>
<html>
<head>
<title>Welcome</title>
</head>
<body>
<center>
<?php
echo 'Three: ';
echo $_SESSION['Three'];
?>
</center>
<p>
<center><a href="checkstatus.php">Check</a></center>
<a href="/Game/logout.php">Logout</a>
</body>
</html>
<?php
}
?>So I think there is something wrong with this:
Code: Select all
$_SESSION['Three'] = $info['three'];Thank you for your time so far!
//Kevin