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

Post here is you are having problems with any of the tutorials.
Post Reply
wistex
Posts: 13
Joined: Fri Jun 17, 2011 10:07 pm

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

Post 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
User avatar
kalipsso
Posts: 30
Joined: Thu Jun 09, 2011 3:03 pm
Location: Bucharest
Contact:

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

Post by kalipsso »

add another } after the one on line 25...it should do it..
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

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

Post by jacek »

this block
if (isset($_POST['username'], $_POST['password'])){
does not have a closing }
Image
wistex
Posts: 13
Joined: Fri Jun 17, 2011 10:07 pm

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

Post by wistex »

kalipsso and jacek

Thank you both. It works like a charm!

Jon
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

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

Post by jacek »

:oops: somehow missed the reply above mine, sorry ;)

good news that you got it working though.
Image
Post Reply