-1

I have this code that processes a user then redirects them to the user homepage.

<?php
    $username = $_POST['username'];
    $password = $_POST['pwd'];

    $file = file_get_contents("userdb.html");
    if(!strpos($file, $username)) {
        echo "Your username was not found in our database. Please go back and try again.";
    } else {
        echo "Redirecting...";
        if (md5($password) == !strpos($file, (md5($password))) {
             echo "Redirecting..."
             header ('Location: ./userhome.php')
        } else {
             print "Whoops! Your password seems to be incorrect. Go back and try again."
        }
    }
?>

And I get the error:

Parse error: syntax error, unexpected '{' in userprocess.php on line 11

Could someone tell me the problem please? I think it may be the if inside of if statement, but what can I do for an alternative? Thanks.

3
  • 1
    Try to use good IDE and you'll see syntax errors marked. NetBeans or PhpStorm. Commented Aug 14, 2011 at 21:26
  • 2
    Are you going to come back soon and ask, why redirection didn't work? Commented Aug 14, 2011 at 21:26
  • Are you really saving usernames and passwords in an html file? Even if you hash and salt, you should still not hand them out. Commented Aug 17, 2014 at 2:22

4 Answers 4

4

Firstly, this line is missing a closing bracket:

if (md5($password) == !strpos($file, (md5($password))) {

Count the number of ( and ) -- they need to match.

When you fix this, you'll still get errors, because PHP statements need to end with semi-colons.

All of the following lines are missing their semi-colon:

echo "Redirecting..."
header ('Location: ./userhome.php')
print "Whoops! Your password seems to be incorrect. Go back and try again."

You need to fix them all before you'll be able to run the program without syntax errors.

Hope that helps.

Sign up to request clarification or add additional context in comments.

3 Comments

Right after I posted this I realized the semicolons (a seriously stupid problem for me) but thank you for the fix of the if statement. It was a well thought out an clear answer. Thank you.
Also, an echo followed by header and print is just too obvious an error to ignore...
@Linus - indeed, but I was already straying outside the bounds of the original question by pointing out the semicolons. :)
1

You are missing a right parenthesis in the line:

if (md5($password) == !strpos($file, (md5($password))) {

Comments

1
<?php
    $username = $_POST['username'];
    $password = $_POST['pwd'];

    $file = file_get_contents("userdb.html");
    if(!strpos($file, $username)) {
        echo "Your username was not found in our database. Please go back and try again.";
    } else {
        echo "Redirecting...";
        if (md5($password) == !strpos($file, md5($password))) {
             echo "Redirecting...";
             header ('Location: ./userhome.php');
        } else {
             print "Whoops! Your password seems to be incorrect. Go back and try again.";
        }
    }
?>

Comments

1

Change

if (md5($password) == !strpos($file, (md5($password)))

to

if (md5($password) == !strpos($file, md5($password)))

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.