Pyroka
09-01-2009, 10:06 AM
RIGHT, I'm getting a error, " Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /var/www/web155/web/index.php on line 73"
My code isn't great I admit, but I just can't see the error :S
Line 73 is:
echo "<p>Thanks for visiting! Please either login below, or <a href="register.php">click here to register</a>.</p>";
Whole code:
<?php include "base.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>User System [Ryan Goodwin, Exeter College]</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<?php
if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))
{
echo "You are now logged in. Username: <b>{$_SESSION['Username']}</b><br /><br /> Email Address: <b>{$_SESSION['EmailAddress']}</b>.";
$id = $_GET["UserID"];
$sql = mysql_query("SELECT `Logged` FROM `Users` WHERE `UserID` = '$id'");
$fetch = mysql_fetch_array($sql);
echo "Number of times logged in: {$fetch["Logged"]}";
// Lets user access the main page. If both sessions are not empty, it lets the session continue.
// !empty is checking whether it is or isnt empty. If empty = true then move onto the next step.
// Session Username is the Username entered on login, and their email is associated with Username and retrieved.
}
elseif(!empty($_POST['Username']) && !empty($_POST['Password']))
{
// MySQL_Real_Escape is a method of clearing the database input. Not completely safe...
$username = mysql_real_escape_string($_POST['username']);
// MD5 is an encryption method which protects Passwors from being found easily by hackers.
// It can be made more advanced, but the standard PHP encryption is good enough for general safety.
$password = md5(mysql_real_escape_string($_POST['Password']));
// Checks the login data using a MYSQL query, selecting the database and then searching to see whether the password matches the Username.
$checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."' AND Password = '".$password."'");
// If statement. If the checklogin is correct and true, then the login is verified and it will submit the user through to their homepage.
if(mysql_num_rows($checklogin) == 1)
{
// Obtains users Email Address for future use.
$row = mysql_fetch_array($checklogin);
$email = $row['EmailAddress'];
// Starts Sessions for Username, Email Address and counts the user as logged into the system.
$_SESSION['Username'] = $username;
$_SESSION['EmailAddress'] = $email;
$_SESSION['LoggedIn'] = 1;
$sql = mysql_query("SELECT `UserID` FROM `Users`");
$fetch = mysql_fetch_array($sql);
mysql_query("UPDATE `Users` SET `Logged` = `Logged` + 1");
// Greeting message on the page, stating successful login.
echo "<h1>Success!</h1>";
echo "<p>Logging into user system...</p>";
echo "<meta http-equiv='refresh' content='=2;index.php' />";
}
else
{ // If the username or password is incorrect then this error comes up:
echo "<h1>Error</h1>";
echo "<p>Your account did not match its password. Please <a href=\"index.php\">click here to try again</a>.</p>";
}
}
else
{
// Login page, the user hasn't logged in yet but is on a login page where user can enter their data.
// When user submits UN/PW, checklogin will run its query again to see whether it's a valid login.
echo "<h1>Member Login</h1>";
echo "<p>Thanks for visiting! Please either login below, or <a href="register.php">click here to register</a>.</p>";
echo "<form method="post" action="index.php" name="loginform" id="loginform">";
echo "<fieldset>";
echo "<label for="username">Username:</label><input type="text" name="username" id="username" /><br />";
echo "<label for="password">Password:</label><input type="password" name="password" id="password" /><br />";
echo "<input type="submit" name="login" id="login" value="Login" />";
echo "</fieldset>";
echo "</form>";
}
?>
Look over and see what the problem is, I'm not too sure about the amount of echo's I've got at the bottom either... It's bugging the hell out of me LOL.
My code isn't great I admit, but I just can't see the error :S
Line 73 is:
echo "<p>Thanks for visiting! Please either login below, or <a href="register.php">click here to register</a>.</p>";
Whole code:
<?php include "base.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>User System [Ryan Goodwin, Exeter College]</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<?php
if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))
{
echo "You are now logged in. Username: <b>{$_SESSION['Username']}</b><br /><br /> Email Address: <b>{$_SESSION['EmailAddress']}</b>.";
$id = $_GET["UserID"];
$sql = mysql_query("SELECT `Logged` FROM `Users` WHERE `UserID` = '$id'");
$fetch = mysql_fetch_array($sql);
echo "Number of times logged in: {$fetch["Logged"]}";
// Lets user access the main page. If both sessions are not empty, it lets the session continue.
// !empty is checking whether it is or isnt empty. If empty = true then move onto the next step.
// Session Username is the Username entered on login, and their email is associated with Username and retrieved.
}
elseif(!empty($_POST['Username']) && !empty($_POST['Password']))
{
// MySQL_Real_Escape is a method of clearing the database input. Not completely safe...
$username = mysql_real_escape_string($_POST['username']);
// MD5 is an encryption method which protects Passwors from being found easily by hackers.
// It can be made more advanced, but the standard PHP encryption is good enough for general safety.
$password = md5(mysql_real_escape_string($_POST['Password']));
// Checks the login data using a MYSQL query, selecting the database and then searching to see whether the password matches the Username.
$checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."' AND Password = '".$password."'");
// If statement. If the checklogin is correct and true, then the login is verified and it will submit the user through to their homepage.
if(mysql_num_rows($checklogin) == 1)
{
// Obtains users Email Address for future use.
$row = mysql_fetch_array($checklogin);
$email = $row['EmailAddress'];
// Starts Sessions for Username, Email Address and counts the user as logged into the system.
$_SESSION['Username'] = $username;
$_SESSION['EmailAddress'] = $email;
$_SESSION['LoggedIn'] = 1;
$sql = mysql_query("SELECT `UserID` FROM `Users`");
$fetch = mysql_fetch_array($sql);
mysql_query("UPDATE `Users` SET `Logged` = `Logged` + 1");
// Greeting message on the page, stating successful login.
echo "<h1>Success!</h1>";
echo "<p>Logging into user system...</p>";
echo "<meta http-equiv='refresh' content='=2;index.php' />";
}
else
{ // If the username or password is incorrect then this error comes up:
echo "<h1>Error</h1>";
echo "<p>Your account did not match its password. Please <a href=\"index.php\">click here to try again</a>.</p>";
}
}
else
{
// Login page, the user hasn't logged in yet but is on a login page where user can enter their data.
// When user submits UN/PW, checklogin will run its query again to see whether it's a valid login.
echo "<h1>Member Login</h1>";
echo "<p>Thanks for visiting! Please either login below, or <a href="register.php">click here to register</a>.</p>";
echo "<form method="post" action="index.php" name="loginform" id="loginform">";
echo "<fieldset>";
echo "<label for="username">Username:</label><input type="text" name="username" id="username" /><br />";
echo "<label for="password">Password:</label><input type="password" name="password" id="password" /><br />";
echo "<input type="submit" name="login" id="login" value="Login" />";
echo "</fieldset>";
echo "</form>";
}
?>
Look over and see what the problem is, I'm not too sure about the amount of echo's I've got at the bottom either... It's bugging the hell out of me LOL.