login function got problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bb nicole
    New Member
    • Jan 2007
    • 127

    login function got problem

    Below is my login function, but it cant display the username correctly, i don't know what is the problem. Thanx..


    LOGIN FUNCTION

    <?php

    extract ($_POST);

    mysql_connect(" localhost","roo t","")
    or die("Cannot connect to the server");

    mysql_select_db ("dreamzdesign" )
    or die("Cannot connect to the database");

    $sql="select username from membership where username='$user name'";

    $result=mysql_q uery($sql)
    or die("Cannot execute query1");

    $num=mysql_num_ rows($result);


    if($num==1) //email valid
    {
    $sql="select username from membership where username='$user name' and password='$pass word'";

    $result2=mysql_ query($sql)
    or die("Cannot execute query");

    $num2=mysql_num _rows($result2) ;
    if($num2>0)
    {
    setcookie("User name", $username, time() + 60 * 60 * 24 * 5);

    include("homepa ge.php");

    }
    else //message send to login.php when wrong password
    {
    $message="The username, $username exists, but you have not entered the correct password! Please try again.<br>";
    include("login. php");
    }
    }
    elseif($num==0) //message send to login.php when email not valid
    {
    $message="The username you entered does not exist! Please try again.<br>";
    include("login. php");
    }



    ?>

    WELCOME MESSAGE

    <?php
    foreach ($_COOKIE as $key => $value)
    ?>
    <h1 align="center"> <? echo $value; ?>, welcome to DreamZDesign !</h1>


    HOMEPAGE

    <?php
    foreach ($_COOKIE as $key => $value)
    ?>

    <h1 align="center"> <? echo $value; ?>, welcome to DreamZDesign !</h1>
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Please read the Posting Guidelines before you post (code) in this forum!

    moderator

    Comment

    • bb nicole
      New Member
      • Jan 2007
      • 127

      #3
      Sorry. Below is my login function, welcome message and homepage. Thanx.

      Login function
      [PHP] <?php

      extract ($_POST);

      mysql_connect(" localhost","roo t","")
      or die("Cannot connect to the server");

      mysql_select_db ("dreamzdesign" )
      or die("Cannot connect to the database");

      $sql="select username from membership where username='$user name'";

      $result=mysql_q uery($sql)
      or die("Cannot execute query1");

      $num=mysql_num_ rows($result);


      if($num==1) //email valid
      {
      $sql="select username from membership where username='$user name' and password='$pass word'";

      $result2=mysql_ query($sql)
      or die("Cannot execute query");

      $num2=mysql_num _rows($result2) ;
      if($num2>0)
      {
      setcookie("User name", $username, time() + 60 * 60 * 24 * 5);

      include("homepa ge.php");

      }
      else //message send to login.php when wrong password
      {
      $message="The username, $username exists, but you have not entered the correct password! Please try again.<br>";
      include("login. php");
      }
      }
      elseif($num==0) //message send to login.php when email not valid
      {
      $message="The username you entered does not exist! Please try again.<br>";
      include("login. php");
      }



      ?>[/PHP]

      Welcome message

      [HTML]<html>
      <head>
      <title>Welcom e <? echo $username; ?></title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      </head>

      <body>

      [PHP]<?php
      foreach ($_COOKIE as $key => $value)
      ?>[/PHP]
      <h1 align="center">[PHP]<? echo $value; ?>[PHP], welcome to DreamZDesign !</h1>
      </body>
      </html>
      [/HTML]



      Homepage

      [PHP]<?php
      foreach ($_COOKIE as $key => $value)
      ?>[/PHP]

      [HTML]<html>
      <head>
      <title>DreamZDe sign</title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      <style type="text/css">
      <!--
      body {
      background-color: #232122;
      }
      body,td,th {
      color: #FFFFFF;
      }
      a:link {
      color: #FFFFFF;
      }
      a:visited {
      color: #FFFFFF;
      }
      a:hover {
      color: #CCCCCC;
      }
      a:active {
      color: #CCCCCC;
      }
      -->
      </style></head>

      <body>
      <p><img src="image/top%20banner.jp g" width="955" height="200"><a href="homepage. php"><img src="button/home.jpg" width="90" height="24" border="0"></a><a href="design.ph p"><img src="button/design%20zone.j pg" width="103" height="24" border="0"></a><a href="gallery.p hp"><img src="button/gallery.jpg" width="102" height="24" border="0"></a><a href="cart.php" ><img src="button/cart.jpg" width="68" height="24" border="0"></a><a href="forum.php "><img src="button/forum.jpg" width="51" height="24" border="0"></a><a href="faq.php"> <img src="button/faq.jpg" width="79" height="24" border="0"></a> <a href="aboutUs.p hp"><img src="button/about%20us.jpg" width="86" height="24" border="0"></a><a href="contactUS .php"><img src="button/contact%20us.jp g" width="121" height="24" border="0"></a>
      </p><p align="center">

      </p>
      <h1 align="center">[PHP]<?php echo $value; ?>[/PHP], welcome to DreamZDesign !</h1>
      <p><img src="image/main%20page.jpg " width="890" height="540"></p>
      <p><img src="image/bottom%20banner .jpg" width="955" height="46"></p>
      </body>
      </html>[/HTML]

      Comment

      • bb nicole
        New Member
        • Jan 2007
        • 127

        #4
        Sorry. Im new in php, below is my login page, login function, welcome message and homepage. Thanks.

        LOGIN FUNCTION

        [PHP]<?php

        extract ($_POST);

        mysql_connect(" localhost","roo t","")
        or die("Cannot connect to the server");

        mysql_select_db ("dreamzdesign" )
        or die("Cannot connect to the database");

        $sql="select username from membership where username='$user name'";

        $result=mysql_q uery($sql)
        or die("Cannot execute query1");

        $num=mysql_num_ rows($result);


        if($num==1) //email valid
        {
        $sql="select username from membership where username='$user name' and password='$pass word'";

        $result2=mysql_ query($sql)
        or die("Cannot execute query");

        $num2=mysql_num _rows($result2) ;
        if($num2>0)
        {
        setcookie("User name", $username, time() + 60 * 60 * 24 * 5);

        include("homepa ge.php");

        }
        else //message send to login.php when wrong password
        {
        $message="The username, $username exists, but you have not entered the correct password! Please try again.<br>";
        include("login. php");
        }
        }
        elseif($num==0) //message send to login.php when email not valid
        {
        $message="The username you entered does not exist! Please try again.<br>";
        include("login. php");
        }



        ?>[/PHP]


        LOGIN PAGE

        [HTML]<html>
        <head>
        <title>DreamZDe sign</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <style type="text/css">
        <!--
        body {
        background-color: #232122;
        }
        body,td,th {
        color: #FFFFFF;
        }
        a:link {
        color: #FFFFFF;
        }
        a:visited {
        color: #FFFFFF;
        }
        a:hover {
        color: #CCCCCC;
        }
        a:active {
        color: #CCCCCC;
        }
        -->
        </style></head>

        <body>
        <p><img src="image/top%20banner.jp g" width="955" height="200">
        </p>
        <p align="center">[PHP]<?php echo $message;?>[/PHP]You MUST login before can use our services. If you don't have username please register <a href="register. php">here.</a> </p>
        <form action='do_logi n.php' method='post'>
        <p align="center"> Name : &nbsp;&nbsp;&nb sp;&nbsp;
        <input type='text' name='username' size='24' maxlength='24'>
        </p>
        <p align="center"> Password :
        <input type='password' name='password' size='24' maxlength='24'>
        </p>
        <p></p>
        <p>
        <center>
        <input type='submit' name='submit' value='login' />
        </center>
        </form>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p><img src="image/bottom%20banner .jpg" width="955" height="46"></p>
        </body>
        </html>[/HTML]


        WELCOME MESSAGE

        [HTML]<html>
        <head>
        <title>Welcom e <? echo $username; ?></title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        </head>

        <body>
        [PHP]<?php
        foreach ($_COOKIE as $key => $value)
        ?>[/PHP]
        <h1 align="center"> <? echo $value; ?>, welcome to DreamZDesign !</h1>
        </body>
        </html>[/HTML]

        HOMEPAGE

        [PHP]<?php
        foreach ($_COOKIE as $key => $value)
        ?>
        [/PHP]

        [HTML]<html>
        <head>
        <title>DreamZDe sign</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <style type="text/css">
        <!--
        body {
        background-color: #232122;
        }
        body,td,th {
        color: #FFFFFF;
        }
        a:link {
        color: #FFFFFF;
        }
        a:visited {
        color: #FFFFFF;
        }
        a:hover {
        color: #CCCCCC;
        }
        a:active {
        color: #CCCCCC;
        }
        -->
        </style></head>

        <body>
        <p><img src="image/top%20banner.jp g" width="955" height="200"><a href="homepage. php"><img src="button/home.jpg" width="90" height="24" border="0"></a><a href="design.ph p"><img src="button/design%20zone.j pg" width="103" height="24" border="0"></a><a href="gallery.p hp"><img src="button/gallery.jpg" width="102" height="24" border="0"></a><a href="cart.php" ><img src="button/cart.jpg" width="68" height="24" border="0"></a><a href="forum.php "><img src="button/forum.jpg" width="51" height="24" border="0"></a><a href="faq.php"> <img src="button/faq.jpg" width="79" height="24" border="0"></a> <a href="aboutUs.p hp"><img src="button/about%20us.jpg" width="86" height="24" border="0"></a><a href="contactUS .php"><img src="button/contact%20us.jp g" width="121" height="24" border="0"></a>
        </p><p align="center">

        </p>
        <h1 align="center">[PHP]<? echo $value; ?>[/PHP], welcome to DreamZDesign !</h1>
        <p><img src="image/main%20page.jpg " width="890" height="540"></p>
        <p><img src="image/bottom%20banner .jpg" width="955" height="46"></p>
        </body>
        </html>[/HTML]

        Comment

        • bb nicole
          New Member
          • Jan 2007
          • 127

          #5
          What is the problem to my login function, it cant show the username correctly when user login, but it will show the name of the first user after the second user login..
          what is the problem..

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            Because you include() the homepage.php script, you can address the php variable $username from it. So instead, why don't you issue a [php]echo "Welcome $username";[/php] from that homepage.php script?

            Ronald :cool:

            Comment

            • bb nicole
              New Member
              • Jan 2007
              • 127

              #7
              thanks.. my login function already success!! Thanks..

              Comment

              Working...