Akenatehm Posted November 30, 2008 Share Posted November 30, 2008 Hey Guys, This script is apart of a login script. It shows up this error: Parse error: syntax error, unexpected T_VARIABLE in /home/kaurlcom/public_html/relayadmin/scripts/login.php on line 8 Here's the code: <?php // we must never forget to start the session session_start(); $errorMessage = ''; if (isset($_POST['username']) && isset($_POST['password'])) { include 'connect.php' $username = $_POST['username']; $password = $_POST['password']; // check if the user id and password combination exist in database $sql = "SELECT username FROM users WHERE username = '$username' AND password = password('$password')"; $result = mysql_query($sql) or die('Query failed. ' . mysql_error()); if (mysql_num_rows($result) == 1) { // the user id and password match, // set the session $_SESSION['db_is_logged_in'] = true; // after login we move to the main page header('Location: home.php'); exit; } else { $errorMessage = 'Sorry, wrong Username or Password'; } } ?> Help would be greatly appreciated! Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 30, 2008 Share Posted November 30, 2008 include needs to be closed with a ; more preferred method is to write <?php include('connect.php'); ?> Quote Link to comment Share on other sites More sharing options...
Akenatehm Posted November 30, 2008 Author Share Posted November 30, 2008 Ugh. Such an obvious one. Damn. Sorry and Thanks. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 30, 2008 Share Posted November 30, 2008 I should make a list of things but a general note of unexpected variable generally means something isn't closed so check the lines above for that one. Quote Link to comment Share on other sites More sharing options...
Akenatehm Posted November 30, 2008 Author Share Posted November 30, 2008 Ok. Now the page just goes blank and it looks like the session doesnt get created at all. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 30, 2008 Share Posted November 30, 2008 Obviously because you have no output on the page you are only setting the variable for the error message in your else portion near the end add echo $errorMessage; and odds are you will see something Quote Link to comment Share on other sites More sharing options...
Akenatehm Posted November 30, 2008 Author Share Posted November 30, 2008 It now giving the $errorMessage "Invalid Username or Password" but the details I am using are in the database. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 30, 2008 Share Posted November 30, 2008 add into the else statement echo "<br />".$sql>"<br />"; Quote Link to comment Share on other sites More sharing options...
Akenatehm Posted November 30, 2008 Author Share Posted November 30, 2008 Ok here's the reply: It has a 1 on the end. Sorry, wrong Username or Password1 Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 30, 2008 Share Posted November 30, 2008 something with the variable $sql is causing the issue Quote Link to comment Share on other sites More sharing options...
Akenatehm Posted November 30, 2008 Author Share Posted November 30, 2008 Any idea what? Quote Link to comment Share on other sites More sharing options...
Akenatehm Posted November 30, 2008 Author Share Posted November 30, 2008 Ok, I think i fixed it. I changed to this: $sql = "SELECT username FROM `users` WHERE username = '$username' AND password = '$password'"; Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 30, 2008 Share Posted November 30, 2008 What ever works you have to read your logic to realize how its working and if you think the credentials are correct and the output says else then odds are your method to checking said credentials are flawed Quote Link to comment Share on other sites More sharing options...
Akenatehm Posted November 30, 2008 Author Share Posted November 30, 2008 It's all working fine now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.