PHP Code:
<?php
include('connect.php');
if($loggedin == '0'){if(isset($_POST['submit'])){
// Make sure all forms were filled out.
if((!isset($_POST['username'])) || (!isset($_POST['pass']))|| ($_POST['username'] == '') || ($_POST['pass'] == ''))die("Please fill out the form completely. <br><br><a href=index.php>Continue</a>");
// Get user's record from database$player = @mysql_query("SELECT id, username, password, registered, lastlogin FROM players WHERE username = '".$_POST['username']."'");$player = @mysql_fetch_assoc($player);
if($player['id'] == false)die("Sorry, that user is not in our database.<br><br><a href=index.php>Back</a>");else if($player['password'] != md5($_POST['pass']))die("Wrong password!<br><br><a href=index.php>Back</a>");
// set session variables$_SESSION['id'] = $player['id'];$_SESSION['username'] = $player['username'];$_SESSION['password'] = $player['password'];
// update last login$date = date("m/d/y");
$update = @mysql_query("UPDATE players SET lastlogin = '$date' WHERE id = '".$_SESSION['id']."'");
echo 'You are now logged in!';
}else{echo 'You are not logged in. <br><br><form action=index.php method=post>Username: <input type=text name=username><br>Password: <input type=password name=pass><br><input type=submit name=submit value=Submit></form>Would you like to <a href=register.php>register?</a>';}}else{echo 'You are logged in! Welcome to my game, '.$_SESSION['username'].'!<br><br><a href=logout.php>Click Here to Logout</a>';
}
?>
That is what I am using on my index.html page. But it doens't work/ shows up in the html. How so I stop it from doing that and making it work? The register script I'm using doen't seem to work either. Make me think that something if off in my database...
PHP Code:
<?php
include('connect.php');
if($loggedin == '1')
die("You can't register another account while you're logged in.");
// Register Script
// So, the register script is a sample of the basic elements of
// coding used in a simple sim game, namely, putting new data
// into databases.
if(isset($_POST['submit']))
{
// trim removes the whitespaces from the beginning and end of text
// this keeps someone from having a username of " "
$uname = trim($_POST['username']);
// Make sure all forms were filled out.
if((!isset($_POST['username'])) || (!isset($_POST['pass']))
|| ($uname == '') || ($_POST['pass'] == ''))
die("Please fill out the form completely. <br><br>
<a href=register.php>Continue</a>");
// Make sure name hasn't already been used.
$check = @mysql_query("SELECT id FROM players WHERE username = '$uname'");
$check = @mysql_num_rows($check);
if($check > 0)
die("Sorry, that username has already been taken. Please try again.
<br><br>
<a href=register.php>Continue</a>");
// Encrypt password
$pass = md5($_POST['pass']);
$date = date("m/d/y");
// Finally, create the record.
$newPlayer = @mysql_query("INSERT INTO players (username, password, registered) VALUES ('$uname', '$pass', '$date')") or die("Error: ".mysql_error());
echo 'You have been registered! You may now <a href=index.php>Log in</a>.';
}
else
{
// A simple example of a form.
echo '<form action=register.php method=post>
Username: <input type=text name=username><br>
Password: <input type=password name=pass><br>
<input type=submit name=submit value=Submit>
</form>';
}
?>
Can anyone help/point out what is wrong? What can I use that will work? I'm totally lost. O.o