PHP Login Problems (with MySQL backend database)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nathan Given

    PHP Login Problems (with MySQL backend database)

    I run a book exchange web site based in PHP with a mysql database.
    Many users have having trouble logging in.

    Here is a description of the problem.

    A user types in his/her username and password and hits login. The
    browser thinks for a bit then the login screen comes up again and
    nothing has happened (except now the username and password fields are
    blank).

    Here is a snippet of the code...

    session_registe r( "email" );
    session_registe r( "passwd" );
    #setcookie( "email", $email, time()+3600*24* 365 );

    I commented out the setcookie function because many users use the same
    computer and they were able to use the same computer with the
    setcookie function in there.

    Please help!

    Thanks in advance!
    --
    Nathan

    Here is all of the code...

    if( $action == "login" )
    {
    $email = trim( $email );
    $passwd = trim( $passwd );
    if( $email == "" ) error( "Please enter your e-mail" );
    if( $passwd == "" ) error( "Please enter your password" );

    dbConnect();
    $result = mysql_query( "SELECT email FROM user WHERE
    email='$email'" ) or error( mysql_error() );
    if( mysql_num_rows( $result ) != 1 ) error( "Sorry, e-mail doesn't
    exist" );
    $result = mysql_query( "SELECT email FROM user WHERE email='$email'
    AND passwd='$passwd '" ) or error( mysql_error() );
    if( mysql_num_rows( $result ) != 1 ) error( "Sorry, invalid
    password" );
    else
    {
    session_registe r( "email" );
    session_registe r( "passwd" );
    # setcookie( "email", $email, time()+3600*24* 365 );
    if( isset( $cat ) ) header( "Location: ./list.php?cat=$c at" );
    if( $cat == "" ) header( "Location: ./account.php" );
    }
    }
  • Guest's Avatar

    #2
    Re: PHP Login Problems (with MySQL backend database)


    "Nathan Given" <ngiven@hotmail .com> wrote in message
    news:f749d926.0 312161850.19db9 45b@posting.goo gle.com...[color=blue]
    > I run a book exchange web site based in PHP with a mysql database.
    > Many users have having trouble logging in.
    >
    > Here is a description of the problem.
    >
    > A user types in his/her username and password and hits login. The
    > browser thinks for a bit then the login screen comes up again and
    > nothing has happened (except now the username and password fields are
    > blank).
    >
    > Here is a snippet of the code...
    >
    > session_registe r( "email" );
    > session_registe r( "passwd" );
    > #setcookie( "email", $email, time()+3600*24* 365 );
    >
    > I commented out the setcookie function because many users use the same
    > computer and they were able to use the same computer with the
    > setcookie function in there.
    >
    > Please help!
    >
    > Thanks in advance!
    > --
    > Nathan
    >
    > Here is all of the code...
    >
    > if( $action == "login" )
    > {
    > $email = trim( $email );
    > $passwd = trim( $passwd );
    > if( $email == "" ) error( "Please enter your e-mail" );
    > if( $passwd == "" ) error( "Please enter your password" );
    >
    > dbConnect();
    > $result = mysql_query( "SELECT email FROM user WHERE
    > email='$email'" ) or error( mysql_error() );
    > if( mysql_num_rows( $result ) != 1 ) error( "Sorry, e-mail doesn't
    > exist" );
    > $result = mysql_query( "SELECT email FROM user WHERE email='$email'
    > AND passwd='$passwd '" ) or error( mysql_error() );
    > if( mysql_num_rows( $result ) != 1 ) error( "Sorry, invalid
    > password" );
    > else
    > {
    > session_registe r( "email" );
    > session_registe r( "passwd" );
    > # setcookie( "email", $email, time()+3600*24* 365 );
    > if( isset( $cat ) ) header( "Location: ./list.php?cat=$c at" );
    > if( $cat == "" ) header( "Location: ./account.php" );
    > }
    > }[/color]

    is your *** if( $action == "login" ) ** loop being called ?
    where is $cat set ?



    Comment

    • Nico

      #3
      Re: PHP Login Problems (with MySQL backend database)

      When the email and the password is held against your database, you should do
      a SELECT email,password FROM user WHERE email='$email' otherwise mySQL
      doesn't return the value for your password field???

      ..Nico

      <xyzzy> schreef in bericht news:hr-dnaIVoYtzWEKiRV n-ig@comcast.com. ..[color=blue]
      >
      > "Nathan Given" <ngiven@hotmail .com> wrote in message
      > news:f749d926.0 312161850.19db9 45b@posting.goo gle.com...[color=green]
      > > I run a book exchange web site based in PHP with a mysql database.
      > > Many users have having trouble logging in.
      > >
      > > Here is a description of the problem.
      > >
      > > A user types in his/her username and password and hits login. The
      > > browser thinks for a bit then the login screen comes up again and
      > > nothing has happened (except now the username and password fields are
      > > blank).
      > >
      > > Here is a snippet of the code...
      > >
      > > session_registe r( "email" );
      > > session_registe r( "passwd" );
      > > #setcookie( "email", $email, time()+3600*24* 365 );
      > >
      > > I commented out the setcookie function because many users use the same
      > > computer and they were able to use the same computer with the
      > > setcookie function in there.
      > >
      > > Please help!
      > >
      > > Thanks in advance!
      > > --
      > > Nathan
      > >
      > > Here is all of the code...
      > >
      > > if( $action == "login" )
      > > {
      > > $email = trim( $email );
      > > $passwd = trim( $passwd );
      > > if( $email == "" ) error( "Please enter your e-mail" );
      > > if( $passwd == "" ) error( "Please enter your password" );
      > >
      > > dbConnect();
      > > $result = mysql_query( "SELECT email FROM user WHERE
      > > email='$email'" ) or error( mysql_error() );
      > > if( mysql_num_rows( $result ) != 1 ) error( "Sorry, e-mail doesn't
      > > exist" );
      > > $result = mysql_query( "SELECT email FROM user WHERE email='$email'
      > > AND passwd='$passwd '" ) or error( mysql_error() );
      > > if( mysql_num_rows( $result ) != 1 ) error( "Sorry, invalid
      > > password" );
      > > else
      > > {
      > > session_registe r( "email" );
      > > session_registe r( "passwd" );
      > > # setcookie( "email", $email, time()+3600*24* 365 );
      > > if( isset( $cat ) ) header( "Location: ./list.php?cat=$c at" );
      > > if( $cat == "" ) header( "Location: ./account.php" );
      > > }
      > > }[/color]
      >
      > is your *** if( $action == "login" ) ** loop being called ?
      > where is $cat set ?
      >
      >
      >[/color]


      Comment

      Working...