Page 1 of 1

Problem with "Register and Login (User Account System)"

Posted: Fri Jun 17, 2011 10:12 pm
by wistex
I recently went through the video tutorial for Register and Login (User Account System). Everything worked great up to the last of the tutorial when I began receiving this error.
Parse error: syntax error, unexpected $end in C:\xampp\htdocs\BETTERPHP\login.php on line 71
Could someone please take a look at my code and tell me if there is an error in the code?
<?php 

include('core/init.inc.php');

$errors = array();

if (isset($_POST['username'], $_POST['password'])){
	if (empty($_POST['username'])){
		$errors[] = 'The username cannot be empty.';	
	}

	if (empty($_POST['password'])){
		$errors[] = 'The password cannot be empty.';	
	}		
	
	if (valid_credentials($_POST['username'], $_POST['password']) === false) {
		$errors[] = 'Username / Password incorrect.';	
	}
	
	if (empty($errors)){
		$_SESSION['username'] = htmlentities($_POST['username']);
		
		header('Location: protected.php');	
		die();
	}

			
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" type="text/css" href="ext/css/style.css" />
    	<title>Login</title>
    </head>
    <body>
            <div>
            <?php
			
			if (empty($errors) === false){
				?>
                <ul>
                	<?php
					
					foreach ($errors as $error){
						echo "<li>{$error}</li>";	
					}
					
					?>
                </ul>
                <?php					
			}else{
				echo 'Need an Account? <a href="register.php">Register here</a>';
			}
            ?>    
            </div>
            <form action="" method="post">
                <p>
                    <label for="username">Username:</label>
                    <input type="text" name="username" id="username" value="<?php if (isset($_POST['username'])) echo htmlentities($_POST['username']); ?>" />
                </p>
                <p>
                    <label for="password">Password:</label>
                    <input type="password" name="password" id="password" />
                </p>
                <p>
                    <input type="submit" value="Login" />
                </p>   
            </form>                   
    </body>
	</html>
Thank you very much.

Jon

Re: Problem with "Register and Login (User Account System)"

Posted: Sat Jun 18, 2011 6:01 am
by kalipsso
add another } after the one on line 25...it should do it..

Re: Problem with "Register and Login (User Account System)"

Posted: Sat Jun 18, 2011 12:42 pm
by jacek
this block
if (isset($_POST['username'], $_POST['password'])){
does not have a closing }

Re: Problem with "Register and Login (User Account System)"

Posted: Sat Jun 18, 2011 4:15 pm
by wistex
kalipsso and jacek

Thank you both. It works like a charm!

Jon

Re: Problem with "Register and Login (User Account System)"

Posted: Sat Jun 18, 2011 4:19 pm
by jacek
:oops: somehow missed the reply above mine, sorry ;)

good news that you got it working though.