billperrotta Posted March 2, 2010 Report Share Posted March 2, 2010 following this tut http://www.youtube.com/watch?v=qs7ekhdQ1Co&feature=related. Getting this error " Parse error: syntax error, unexpected T_VARIABLE in /homepages/21/d176117763/htdocs/login.php on line 13" Not sure why maybe I have a bad eye but this looks correct. see login.php below <?php session_start(); include ('mysql.php'); if (isset ($_POST['submit'])); { $username = mysql_escape_string($_POST['username']); $password = mysql_escape_string(sha1 ($_POST['password'])); if (!empty ($username) && !empty ($password)) { $sql = myql_query ("SELECT * FROM users WHERE username ='" $username "' AND user_password='" $password "' LIMIT 1"); if (mysql_num_rows ($sql) > 0 { $_SESSION['loggedin'] = true; $_SESSION['username'] = $username; echo 'you are now logged in!'; }else { echo 'your username and/or password is incorrect!'; } echo ' Username: Password: '; ?> Quote Link to comment Share on other sites More sharing options...
Wickham Posted March 2, 2010 Report Share Posted March 2, 2010 Should you have a ; in here:- if (isset ($_POST['submit'])); { I looked at similar code in my forms and there is no ; but it isn't line 13 of your code, so I'm not sure. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted March 2, 2010 Report Share Posted March 2, 2010 Wickham is correct -- that is a potential issue, though like he said, I'm not sure if that is the source of the error. Also, you're missing a few closing "}". Perhaps you didn't paste the whole code... but you have four opening "{" and only two "}". I think the source of the problem is this line though: if (mysql_num_rows ($sql) > 0 { You're missing a closing ")". It should be: if (mysql_num_rows ($sql) > 0) { Quote Link to comment Share on other sites More sharing options...
krillz Posted March 2, 2010 Report Share Posted March 2, 2010 You seem to have screwed up the query ("SELECT * FROM users WHERE username ='" $username "' AND user_password='" $password "' LIMIT 1"); '" $username "' test this instead: "SELECT * FROM users WHERE username ='$username' AND user_password='$password' LIMIT 1" Quote Link to comment Share on other sites More sharing options...
BeeDev Posted March 2, 2010 Report Share Posted March 2, 2010 You can connect a string with a variable using a dot or just include the variable inside the string as Krillz points out above - php works either way. ("SELECT * FROM users WHERE username ='" . $username . "' AND user_password='" . $password . "' LIMIT 1"); Quote Link to comment Share on other sites More sharing options...
billperrotta Posted March 2, 2010 Author Report Share Posted March 2, 2010 Wickham is correct -- that is a potential issue, though like he said, I'm not sure if that is the source of the error. Also, you're missing a few closing "}". Perhaps you didn't paste the whole code... but you have four opening "{" and only two "}". I think the source of the problem is this line though: if (mysql_num_rows ($sql) > 0 { You're missing a closing ")". It should be: if (mysql_num_rows ($sql) > 0) { Changed it like you said see below. but it is complaining about this line 13 "WHERE username ='" $username "' AND" I know this because vi and Quanta tell me the line numbers. Not sure how to correct this. "Parse error: syntax error, unexpected T_VARIABLE in /homepages/21/d176117763/htdocs/login.php on line 13" <?php session_start(); include ('mysql.php'); if (isset ($_POST['submit'])) { $username = mysql_escape_string($_POST['username']); $password = mysql_escape_string(sha1 ($_POST['password'])); if (!empty ($username) && !empty ($password)) { $sql = myql_query ("SELECT * FROM users WHERE username ='" $username "' AND user_password='" $password "' LIMIT 1"); if (mysql_num_rows ($sql) > 0) { $_SESSION['loggedin'] = true; $_SESSION['username'] = $username; echo 'you are now logged in!'; }else { echo 'your username and/or password is incorrect!'; } echo ' Username: Password: '; ?> Quote Link to comment Share on other sites More sharing options...
falkencreative Posted March 2, 2010 Report Share Posted March 2, 2010 You still are missing two closing "}". Fix that, then report back. Quote Link to comment Share on other sites More sharing options...
billperrotta Posted March 2, 2010 Author Report Share Posted March 2, 2010 You still are missing two closing "}". Fix that, then report back. I did what you said see the updated login.php pasted below. noticing it looks like line 11 is not closed. not sure where the bracket goes to close it. same error right now. <?php session_start(); include ('mysql.php'); if (isset ($_POST['submit'])) { $username = mysql_escape_string($_POST['username']); $password = mysql_escape_string(sha1 ($_POST['password'])); if (!empty ($username) && !empty ($password)) { $sql = myql_query ("SELECT * FROM users WHERE username ='" $username "' AND user_password='" $password "' LIMIT 1"); if (mysql_num_rows ($sql) > 0) { $_SESSION['loggedin'] = true; $_SESSION['username'] = $username; echo 'you are now logged in!'; }else { echo 'your username and/or password is incorrect!'; } else { echo ' Username: Password: '; } ?> Quote Link to comment Share on other sites More sharing options...
billperrotta Posted March 2, 2010 Author Report Share Posted March 2, 2010 You still are missing two closing "}". Fix that' date=' then report back.[/quote'] I did what you said see the updated login.php pasted below. noticing it looks like line 11 is not closed. not sure where the bracket goes to close it. same error right now. <?php session_start(); include ('mysql.php'); if (isset ($_POST['submit'])) { $username = mysql_escape_string($_POST['username']); $password = mysql_escape_string(sha1 ($_POST['password'])); if (!empty ($username) && !empty ($password)) { $sql = myql_query ("SELECT * FROM users WHERE username ='" $username "' AND user_password='" $password "' LIMIT 1"); if (mysql_num_rows ($sql) > 0) { $_SESSION['loggedin'] = true; $_SESSION['username'] = $username; echo 'you are now logged in!'; }else { echo 'your username and/or password is incorrect!'; } else { echo ' Username: Password: '; } ?> this line "if (!empty ($username) && !empty ($password)) {" Where do i put the "}" Quote Link to comment Share on other sites More sharing options...
billperrotta Posted March 2, 2010 Author Report Share Posted March 2, 2010 You still are missing two closing "}". Fix that' date=' then report back.[/quote'] I did what you said see the updated login.php pasted below. noticing it looks like line 11 is not closed. not sure where the bracket goes to close it. same error right now. <?php session_start(); include ('mysql.php'); if (isset ($_POST['submit'])) { $username = mysql_escape_string($_POST['username']); $password = mysql_escape_string(sha1 ($_POST['password'])); if (!empty ($username) && !empty ($password)) { $sql = myql_query ("SELECT * FROM users WHERE username ='" $username "' AND user_password='" $password "' LIMIT 1"); if (mysql_num_rows ($sql) > 0) { $_SESSION['loggedin'] = true; $_SESSION['username'] = $username; echo 'you are now logged in!'; }else { echo 'your username and/or password is incorrect!'; } else { echo ' Username: Password: '; } ?> this line "if (!empty ($username) && !empty ($password)) {" Where do i put the "}" Another update my latest. still same error in line 13. see below <?php session_start(); include ('mysql.php'); if (isset ($_POST['submit'])) { $username = mysql_escape_string($_POST['username']); $password = mysql_escape_string(sha1 ($_POST['password'])); } if (!empty ($username) && !empty ($password)) { $sql = myql_query ("SELECT * FROM users } WHERE username ='" $username "' AND user_password='" $password "' LIMIT 1"); if (mysql_num_rows ($sql) > 0) { $_SESSION['loggedin'] = true; $_SESSION['username'] = $username; echo 'you are now logged in!'; }else { echo 'your username and/or password is incorrect!'; } echo ' Username: Password: '; ?> ~ My new latest below. same error on line 13. <?php session_start(); include ('mysql.php'); if (isset ($_POST['submit'])) { $username = mysql_escape_string($_POST['username']); $password = mysql_escape_string(sha1 ($_POST['password'])); } if (!empty ($username) && !empty ($password)) { $sql = myql_query ("SELECT * FROM users } WHERE username ='" $username "' AND user_password='" $password "' LIMIT 1"); if (mysql_num_rows ($sql) > 0) { $_SESSION['loggedin'] = true; $_SESSION['username'] = $username; echo 'you are now logged in!'; }else { echo 'your username and/or password is incorrect!'; } { else echo ' Username: Password: '; } ?> Quote Link to comment Share on other sites More sharing options...
falkencreative Posted March 2, 2010 Report Share Posted March 2, 2010 OK, this is the corrected code: Basically, you had brackets in the wrong places, and your SQL line didn't include proper concatenation (you needed "." between your variables.) http://www.phpf1.com/tutorial/php-string-concatenation.html > session_start(); include ('mysql.php'); if (isset ($_POST['submit'])) { $username = mysql_escape_string($_POST['username']); $password = mysql_escape_string(sha1 ($_POST['password'])); if (!empty ($username) && !empty ($password)) { $sql = myql_query ("SELECT * FROM users WHERE username ='" . $username . "' AND user_password='" . $password . "' LIMIT 1"); if (mysql_num_rows ($sql) > 0) { $_SESSION['loggedin'] = true; $_SESSION['username'] = $username; echo 'you are now logged in!'; } else { echo 'your username and/or password is incorrect!'; } } } else { echo '</pre> <form action="login.php" method="post"> Username: Password: </form>';<br>}<br><br Also, to get back to you regarding PHP editors... On Windows I use Notepad++ (free). On Linux, you might want to look at Vim or SciTE (both free). If you aren't already using something that provides code highlighting, I'd really encourage you to find an editor that does -- it'll catch some of your errors, such as the incorrect curly bracket placement. You might also want to go through some of the free video tutorials on killerphp.com (http://killerphp.com/tutorials/beginners-php/) and phpvideotutorials.com (http://phpvideotutorials.com/free). My impression is that you may want to get a foundation in PHP bsics before you dive into creating a login. A lot of the issues you are encountering would be solved by watching some of those videos. Quote Link to comment Share on other sites More sharing options...
billperrotta Posted March 2, 2010 Author Report Share Posted March 2, 2010 OK, this is the corrected code: Basically, you had brackets in the wrong places, and your SQL line didn't include proper concatenation (you needed "." between your variables.) http://www.phpf1.com/tutorial/php-string-concatenation.html <?php session_start(); include ('mysql.php'); if (isset ($_POST['submit'])) { $username = mysql_escape_string($_POST['username']); $password = mysql_escape_string(sha1 ($_POST['password'])); if (!empty ($username) && !empty ($password)) { $sql = myql_query ("SELECT * FROM users WHERE username ='" . $username . "' AND user_password='" . $password . "' LIMIT 1"); if (mysql_num_rows ($sql) > 0) { $_SESSION['loggedin'] = true; $_SESSION['username'] = $username; echo 'you are now logged in!'; } else { echo 'your username and/or password is incorrect!'; } } } else { echo ' Username: Password: '; } ?> Also, to get back to you regarding PHP editors... On Windows I use Notepad++ (free). On Linux, you might want to look at Vim or SciTE (both free). If you aren't already using something that provides code highlighting, I'd really encourage you to find an editor that does -- it'll catch some of your errors, such as the incorrect curly bracket placement. You might also want to go through some of the free video tutorials on killerphp.com (http://killerphp.com/tutorials/beginners-php/) and phpvideotutorials.com (http://phpvideotutorials.com/free). My impression is that you may want to get a foundation in PHP bsics before you dive into creating a login. A lot of the issues you are encountering would be solved by watching some of those videos. Thanks for the help. Might try the tuts you mentioned. Yes Vim Vi both have the highlighting. But Quanta seems to have even more features plus the highlighting. I installed it with my package manager because crazyflya was using it in the tut example. I can see yellow highlighting when i hover over brackets that have both the open and close. I will implement the last solution in this post. I want to create php login files that I can reuse when I create simple websites. Sometimes when I follow the examples for the login creation to the t it still has issues. I see why the tuts would be helpful. Thanks again. 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.
Note: Your post will require moderator approval before it will be visible.