I've been working on this for awhile to to get it working..
any help would be great!! thxs!
index2.php
Code: Select all
<?php
session_start();
if(isset($_SESSION['username'])){
?>
<p><a href="index2.php">Index</a> | <a href="shop.php">Shop</a> | <a href="logout.php">Logout</a></p>
<p>Username:
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("textgame") or die(mysql_error());
echo " " . $_SESSION['username'];
?>
</p>
<p>Gold: <?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("textgame") or die(mysql_error());
echo " " . $_SESSION['gold'];
?></p>
Inventory:
<br />
<?php
//connect
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("register") or die(mysql_error());
$query = "SELECT item_name FROM items";
//0 or 1 situation
$field = ($row['item_name'] == 0) ? 0 : $row['hoe'];
if($field == 0){
//show nothing
}else{
echo Hoe;
}
}else{
header('Location: login.html');
}
?>Code: Select all
<?php
ob_start();
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="textgame"; // Database name
$tbl_name="users"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$username = (isset($_POST['username'])) ? mysql_real_escape_string($_POST['username']) : FALSE;
$password1 = (isset($_POST['password1'])) ? $_POST['password1'] : FALSE;
$password2 = (isset($_POST['password2'])) ? $_POST['password2'] : FALSE;
if(!$username) die('username not set');
if(!$password1) die('Password1 not set');
else $password1 = md5($password1);
if(!$password2) die('Password2 not set');
else $password2 = md5($password2);
$query = "SELECT * FROM users WHERE username='$username' AND password1='$password1' AND password2='$password2'";
$result = mysql_query($query) or die( mysql_error());
$count=mysql_num_rows($result);
if($count==1){
session_register("username");
$_SESSION['username'] = $username;
header("location:index2.php");
}
else {
echo "Wrong Username or Password";
}
//start up the gold
session_start();
$queryy = "SELECT gold FROM user_stats WHERE username='$username'";
session_register("gold");
$row = mysql_fetch_assoc($queryy);
$_SESSION['gold'] = $row['gold'];
//end of start up gold
ob_end_flush();
?>