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! Link to comment https://forums.phpfreaks.com/topic/134804-solved-unexpected-t_variable/ 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'); ?> Link to comment https://forums.phpfreaks.com/topic/134804-solved-unexpected-t_variable/#findComment-701977 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. Link to comment https://forums.phpfreaks.com/topic/134804-solved-unexpected-t_variable/#findComment-701980 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. Link to comment https://forums.phpfreaks.com/topic/134804-solved-unexpected-t_variable/#findComment-701981 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. Link to comment https://forums.phpfreaks.com/topic/134804-solved-unexpected-t_variable/#findComment-701982 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 Link to comment https://forums.phpfreaks.com/topic/134804-solved-unexpected-t_variable/#findComment-701983 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. Link to comment https://forums.phpfreaks.com/topic/134804-solved-unexpected-t_variable/#findComment-701987 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 />"; Link to comment https://forums.phpfreaks.com/topic/134804-solved-unexpected-t_variable/#findComment-701989 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 Link to comment https://forums.phpfreaks.com/topic/134804-solved-unexpected-t_variable/#findComment-701993 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 Link to comment https://forums.phpfreaks.com/topic/134804-solved-unexpected-t_variable/#findComment-701995 Share on other sites More sharing options...
Akenatehm Posted November 30, 2008 Author Share Posted November 30, 2008 Any idea what? Link to comment https://forums.phpfreaks.com/topic/134804-solved-unexpected-t_variable/#findComment-701997 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'"; Link to comment https://forums.phpfreaks.com/topic/134804-solved-unexpected-t_variable/#findComment-701998 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 Link to comment https://forums.phpfreaks.com/topic/134804-solved-unexpected-t_variable/#findComment-701999 Share on other sites More sharing options...
Akenatehm Posted November 30, 2008 Author Share Posted November 30, 2008 It's all working fine now. Link to comment https://forums.phpfreaks.com/topic/134804-solved-unexpected-t_variable/#findComment-702003 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.