Jump to content

Error in Line 13 of my login.php


billperrotta

Recommended Posts

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:

 

';

 

 

 

 

 

 

 

 

 

 

 

 

?>

Link to comment
Share on other sites

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) {

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

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:

 

';

 

 

 

 

 

 

 

 

 

 

 

 

?>

Link to comment
Share on other sites

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:

 

';

 

}

 

 

 

 

 

 

 

 

 

 

 

 

?>

Link to comment
Share on other sites

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 "}"

Link to comment
Share on other sites

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:

 

';

 

}

 

 

 

 

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. :)

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...