kringshot Posted May 27, 2009 Share Posted May 27, 2009 I'm trying to create a basic log in system using a tutorial that I have been given. Now I've set up a few php files that interact with each other and such, the problem I am getting is a parse error that says it is on the last line of the main login.php. The only thing on this line is </html> however and I can't see any other errors on the page. Any help with fixing this would be helpful. Code is below for login.php, sorry if its sloppy, i'm new to PHP. If the problem somehow lies in any of the other files (I have pupils.php, connect.php and constants.php which are all hidden from the user and used as authentication for the login) Thanks! <?php session_start(); require_once 'classes/pupils.php'; $pupils = new pupils(); //If $_POST is present and both username and password are filled out then if($_POST && !empty($_POST['username']) && !empty($_POST['password'])) { $response = $pupils->validate_user($_POST['username'], $_POST['password']); ?> <!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" /> <title>Login Page</title> <link href="defaultstyle.css" rel="stylesheet" type="text/css" /> </head> <body class="body"> <h2 class="header2">Welcome To Kraft!</h2> <p class="text2">The free social site for Herne Junior pupils!</p> <div id="login"> <form class="login" action="" method="post"> <h3 class="header3">Login Page</h3> <p> <label class="text1" for="username">Username: <input type="text" name="username" /></label><small class="text1">This is where you enter your username (If you've forgotten it, don't worry! Ask your teacher!)</small><br /> </p> <p> <label class="text1" for="password">Password: <input type="password" name="password" /></label><small class="text1">This is where you enter your password (Again if you've forgotten it, your teacher can help!)</small><br /> </p> <p> <input type="submit" value="Login" name="login" id="login" /> </p> </form> <?php if (isset($response)) echo "<h4 class='text1'>" . $response . "</h4>"; ?> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/159864-having-trouble-with-a-parse-error-using-php-and-mysql/ Share on other sites More sharing options...
Ken2k7 Posted May 27, 2009 Share Posted May 27, 2009 You never closed the opening brace "{" in your first if statement. Link to comment https://forums.phpfreaks.com/topic/159864-having-trouble-with-a-parse-error-using-php-and-mysql/#findComment-843125 Share on other sites More sharing options...
stelthius Posted May 27, 2009 Share Posted May 27, 2009 This should be it very simple fix, sometimes very easily missed tho.. <?php session_start(); require_once 'classes/pupils.php'; $pupils = new pupils(); //If $_POST is present and both username and password are filled out then if($_POST && !empty($_POST['username']) && !empty($_POST['password'])) { $response = $pupils->validate_user($_POST['username'], $_POST['password']); } ?> Link to comment https://forums.phpfreaks.com/topic/159864-having-trouble-with-a-parse-error-using-php-and-mysql/#findComment-843128 Share on other sites More sharing options...
kringshot Posted May 27, 2009 Author Share Posted May 27, 2009 gaaaah! I was looking for ages, can't believe I missed it. Thanks guys =D Link to comment https://forums.phpfreaks.com/topic/159864-having-trouble-with-a-parse-error-using-php-and-mysql/#findComment-843136 Share on other sites More sharing options...
kringshot Posted May 27, 2009 Author Share Posted May 27, 2009 Another things come up now, I seem to be having a problem with restricting access to index.php. I can make it either stop access all together by rerouting all requests to login.php (even if correct login information is supplied) or it won't restrict anything, and even when the session cookie is deleted it will still let someone link directly to index.php. If theres something simple missing here i am going to kick myself! Thanks a million guys index.php <?php require_once 'classes/pupils.php'; $pupils = new pupils(); $pupils->confirm_pupil(); ?> <!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" /> <title>index</title> <link href="defaultstyle.css" rel="stylesheet" type="text/css" /> </head> <body class="text1"> <?php $user = $_POST['username']; echo "Welcome to the site, Phil!";?> <a href="login.php?status=log_out">Log Out</a> </body> </html> pupils.php <?php require 'connect.php'; class pupils { //ensure_credentials will hold the value true if a user login has been accepted function validate_user($user,$pass){ $mysql = New connect(); $ensure_credentials = $mysql->verify_user_pass($user, $pass); //If ensure_credentials holds true then status is authorised and user is sent to the index page if($ensure_credentials){ $_SESSION['status'] = 'authorised'; header("location: index.php"); } else return "Please enter a correct username and/or password!"; } //The log out function that will remove the session and cookie from a computer and log a user out. function log_out(){ if(isset($_SESSION['status'])){ unset($_SESSION['status']); if(isset($_COOKIE[session_name()])) setcookie(session_name(), '', time() - 1000); session_destroy(); } } function confirm_pupil() { session_start(); if($_SESSION['status'] !='authorised') header("location: login.php"); } } Link to comment https://forums.phpfreaks.com/topic/159864-having-trouble-with-a-parse-error-using-php-and-mysql/#findComment-843215 Share on other sites More sharing options...
kringshot Posted May 27, 2009 Author Share Posted May 27, 2009 Help with this would be much appreciated, I've tried so many things and looked in my books but everything to me looks good! I need another set of eyes that no what there doing to take a look as i've been staring at this for so long now... Thanks Link to comment https://forums.phpfreaks.com/topic/159864-having-trouble-with-a-parse-error-using-php-and-mysql/#findComment-843406 Share on other sites More sharing options...
kringshot Posted May 27, 2009 Author Share Posted May 27, 2009 Sorry to bump this up again just really stuck with this problem! I've gone as far on with the site as I can without this being resolved and nothing I can find can help! eek Link to comment https://forums.phpfreaks.com/topic/159864-having-trouble-with-a-parse-error-using-php-and-mysql/#findComment-843545 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.