Page 1 of 1

Another Login Error

Posted: Fri Mar 25, 2005 4:21 pm
by anthony88guy
I am making a login using sessions, when the user and pass is checked to the database and returns true then Session record their username, and gives permission. Redirected to another page, here is the code of my page.



I get an error on line 55: Parse error: parse error, unexpected $

Can anyone shed any light why it won't work?

Posted: Fri Mar 25, 2005 4:25 pm
by phpScott
look closely at line 4 of your posted code. line 3 has { but I don't see the }

phpscott

Posted: Fri Mar 25, 2005 4:44 pm
by anthony88guy
thanks a million, i was looking at the bottom.

Posted: Fri Mar 25, 2005 5:00 pm
by Ambush Commander
Yeah, problems with missing braces always cause the most pain because the parser will always throw an error indicating something's wrong at the bottom of the page.

The solution? Make sure you indent your logic.

Posted: Fri Mar 25, 2005 5:03 pm
by John Cartwright
there are several editors outside that will show their sister bracket -- one being PHP Designer 2005.. indending helps too

Posted: Fri Mar 25, 2005 5:03 pm
by feyd
that's exactly why I always use this sort of style

Code: Select all

if($somevar)
{
    echo 'something';
}
else
{
    echo 'something else';
}

Posted: Fri Mar 25, 2005 5:08 pm
by Ambush Commander
Hmm... I prefer a K&R (EDIT-the Rcharacter got munged) style for conditionals:

Code: Select all

if ($bang == 'big') {
    //More stuff
} elseif ($foo == 'lob' && empty($mar)) {
    //Stuff
} else {
    exit;
}
and BSD for functions (which is the style Feyd uses)

Code: Select all

function general_convertChar()
{
    return 0;
}
Bracing styles are a matter of personal preference, but make sure you're consistent.

Posted: Fri Mar 25, 2005 5:17 pm
by anthony88guy
I am pretty new to php, and havent really developed a style to writing my code yet. Thanks again though, my login works. :)

Posted: Fri Mar 25, 2005 5:21 pm
by Ambush Commander
Then now is the time to start. Get into good habits early (I bemoan myself over poorly written code that I still use).