Okay, I've got 2 tables; petgamex_users and petgamex_pets.
In users the fields are id username password email and fullname.
In pets the fields are id, name, power, defence, wisdom, speed, hit_points and image_path.
This is my authenticate.php file:
<?
include "dbconnect.php";
$auth = false; // Assume user is not authenticated
if (isset( $php_petgamexuser ) && isset($php_petgamexpass) && isset($php_petgamexpet)) {
$sql = "SELECT * FROM petgamex_users WHERE
username = '$php_petgamexuser' AND
password = '$php_petgamexpass'";
"SELECT * FROM petgamex_pets WHERE
name = '$php_petgamexpet'";
// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( "Unable to execute query." );
// Get number of rows in $result.
$num = mysql_numrows( $result );
if ( $num != 0 ) {
// A matching row was found - the user is authenticated.
$auth = true;
}
}
if ( !$auth ) {
echo "
<html>
<head>
<title>Pet Game X</title>
<link rel=stylesheet type=text/css href=css.css>
</head>
<body bottommargin=\"0\" rightmargin=\"0\" leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">
<table width=\"100%\" height=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td align=center valign=middle height=\"100%\" width=\"100%\">
<form method=\"post\" action=\"$PHP_SELF\">
<table border=\"0\" cellspacing=\"1\" cellpadding=\"0\">
<tr>
<td colspan=\"2\" align=center>
<img src=\"images/logo.gif\">
</td>
</tr>
<tr>
<td align=right><strong>User Name:  </strong></td>
<td>
<input name=\"php_petgamexuser\" type=\"text\">
</td>
</tr>
<tr>
<td align=right><strong>Password:  </strong></td>
<td>
<input name=\"php_petgamexpass\" type=\"password\">
</td>
</tr>
<tr>
<td>
<input name=\"php_petgamexpet\" value=\"$php_petgamexpet\" type=\"hidden\">
</td>
</tr>
<tr>
<td colspan=2 align=right>
<input type=\"submit\" value=\"Login\">
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan=2 align=center>
<a href=\"register.php\">Not Registered?<br>Click Here</a>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
";
exit;
}
?>
This is my index.php:
<?
session_start();
include "authenticate.php";
echo "<html>
<head>
<title>Pet Game X</title>
<link href='css.css' rel='stylesheet' type='text/css'>
<script type='text/javascript'>
function popPetProfile(){ var pageURL = 'petprofile.php';
var width = 500;
var height = 1000;
window.open(pageURL,'win',width='+width+',height='+height+',top='+parseInt((screen.height - height) / 2)+',left='+parseInt((screen.width - width) / 2)+',scrollbars=no,resizeable=no');}
</script>
</head>
<body>
<center>
<table border='2' cellspacing='1' bordercolor='#808080' width='600' height='550' id='maintable' align='left' bordercolorlight='#808080' bordercolordark='#808080'>
<tr>
<td width='140' height='90'>
<img src='images/logo.gif' width='140' height='90'></td>
<td width='450' height='90'>
<p align='center'><font face='Comic Sans MS' size='7'>Pet Game X</font></td>
</tr>
<tr>
<td width='140' height='450' align='center' valign='top'>
<p align='center'>
<font face='Comic Sans MS' size='2'>User: $php_petgamexuser";
<font face='Comic Sans MS' size='2'>Pet: '$php_petgamexpet';
</font>
<p align="center">
<br>
<font face='Comic Sans MS'>News</font><br>
<font face='Comic Sans MS'>Your house</font><br>
<font face='Comic Sans MS'>Shops</font><br>
<font face='Comic Sans MS'>Battlecenter</font><br>
<a href ='javascript:popPetProfile();'>Your Pet<a>
<p align='center'>
</td>
<td width='450' height='450'> </td>
</tr>
</table>
</center>
</body>
</html>";
?>
This is my petprofile.php:
<?
include 'dbconnect.php';
$query = "SELECT * FROM petgamex_pets";
$power = mysql_query($query) or die("Query failed : " . mysql_error());
$defence = mysql_query($query) or die("Query failed : " . mysql_error());
$wisdom = mysql_query($query) or die("Query failed : " . mysql_error());
$speed = mysql_query($query) or die("Query failed : " . mysql_error());
$name = mysql_query($query) or die("Query failed : " . mysql_error());
$age = mysql_query($query) or die("Query failed : " . mysql_error());
echo "<html>
<head>
<title>Pet Profile</title>
<link href='css.css' rel='stylesheet' type='text/css'>
</head>
<body>
Pet Name: $line = mysql_fetch_array($name, MYSQL_ASSOC$line = mysql_fetch_array($result, MYSQL_ASSOC
<br>
Adopted on: $age
<br><br>
Stats:
<br>
Power: $power
<br>
Defence: $defence
<br>
Wisdom: $wisdom
<br>
Speed: $speed
<br>
<img src = images/pets/pet1.gif>
</body>
</html>";
?>
Can someone tell me how to:
a; print a value from a table depending on the current user
b; link a user name in one table to a pet id in another so that when a user logs in their pet name is displayed. A sql dump would be useful 😉