Results 1 to 15 of 15

Thread: [RESOLVED] Login Script not working...

  1. #1

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Resolved [RESOLVED] Login Script not working...

    HTML Code:
    <? session_start() ?>
    <html>
    <head>
     <title>Login</title>
    </head>
    
    <body>
     <h2>Login</h2>
     <?
    	$links = "<a href='main.php'>Click here to proceed to the main page</a>
    	if($user && $pass) {
    		if($logged_in_user == $user) {
    			echo "."$user"." you are already logged in. <br><br>";
    			echo $links;
    			exit;
    		}
    
    		$db = mysql_connect("localhost");
    		mysql_select_db("userlists", $db);
    		$result = mysql_query("SELECT * FROM users WHERE name = '".$users."' 
    					AND password = PASSWORD('".$pass."')");
    		if(!$result) {
    			echo "Sorry, there has been a technical hitch. We cannot enter your details";
    			exit;
    		}
    		if(mysql_num_rows($result) > 0) {
    			$logged_in_user = $user;
    			session_register("logged_in_user");
    			echo "Welcome, ".$logged_in_user.". <br><br>";
    			echo $links;
    			exit;
    		} else {
    			echo "Invalid login. Please try again. <br><br>";
    		}
    	} else if($user || $pass) {
    		echo "Please fill in both fields. <br><br";
    	}
    
     ?>
     <form method=post action="login.php">
     Your Username:
     <input name="user" type=text maxlength=20 size=20>
     <br>
     Your Password:
     <input name="pass" type=Password maxlength=10 size=10>
     <br>
     <input type=submit value="Login">
     </form>
    </body>
    My usual boring signature: Something

  2. #2
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: Login Script not working...

    What exactly is your problem. Any errors, btw to need to close the double quote here
    PHP Code:
    $links "<a href='main.php'>Click here to proceed to the main page</a>"

  3. #3

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Login Script not working...

    http://dclamp.homtek.net/login.php
    that is where the script is
    My usual boring signature: Something

  4. #4
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Login Script not working...

    When you run your script it tells you what and where the error is....

    PHP Code:
    Parse errorsyntax errorunexpected '}' in /usr/home/homtek/public_html/dclamp/login.php on line 17 

  5. #5
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Login Script not working...

    Here you go

    By modifing the code in bold everything now shows as it should.
    PHP Code:
    <? session_start() ?>
    <html>
    <head>
     <title>Login</title>
    </head>

    <body>
     <h2>Login</h2>
     <?
        $links = "<a href='main.php'>Click here to proceed to the main page</a>";
        if($user && $pass) {
            if($logged_in_user == $user) {
                [B]echo $user." you are already logged in. <br><br>";[/B]            echo $links;
                exit;
            }

            $db = mysql_connect("localhost");
            mysql_select_db("userlists", $db);
            $result = mysql_query("SELECT * FROM users WHERE name = '".$users."' 
                        AND password = PASSWORD('".$pass."')");
            if(!$result) {
                echo "Sorry, there has been a technical hitch. We cannot enter your details";
                exit;
            }
            if(mysql_num_rows($result) > 0) {
                $logged_in_user = $user;
                session_register("logged_in_user");
                echo "Welcome, ".$logged_in_user.". <br><br>";
                echo $links;
                exit;
            } else {
                echo "Invalid login. Please try again. <br><br>";
            }
        } else if($user || $pass) {
            echo "Please fill in both fields. <br><br";
        }

     ?>
     <form method=post action="login.php">
     Your Username:
     <input name="user" type=text maxlength=20 size=20>
     <br>
     Your Password:
     <input name="pass" type=Password maxlength=10 size=10>
     <br>
     <input type=submit value="Login">
     </form>
    </body>

  6. #6

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Login Script not working...

    nothing is bolded
    My usual boring signature: Something

  7. #7
    Addicted Member
    Join Date
    Jan 2006
    Posts
    247

    Re: Login Script not working...

    Quote Originally Posted by dclamp
    HTML Code:
    <? session_start() ?>
    <html>
    <head>
     <title>Login</title>
    </head>
    
    <body>
     <h2>Login</h2>
     <?
    	$links = "<a href='main.php'>Click here to proceed to the main page</a>
    	if($user && $pass) {
    		if($logged_in_user == $user) {
    			echo "."$user"." you are already logged in. <br><br>";
    			echo $links;
    			exit;
    		}
    
    		$db = mysql_connect("localhost");
    		mysql_select_db("userlists", $db);
    		$result = mysql_query("SELECT * FROM users WHERE name = '".$users."' 
    					AND password = PASSWORD('".$pass."')");
    		if(!$result) {
    			echo "Sorry, there has been a technical hitch. We cannot enter your details";
    			exit;
    		}
    		if(mysql_num_rows($result) > 0) {
    			$logged_in_user = $user;
    			session_register("logged_in_user");
    			echo "Welcome, ".$logged_in_user.". <br><br>";
    			echo $links;
    			exit;
    		} else {
    			echo "Invalid login. Please try again. <br><br>";
    		}
    	} else if($user || $pass) {
    		echo "Please fill in both fields. <br><br";
    	}
    
     ?>
     <form method=post action="login.php">
     Your Username:
     <input name="user" type=text maxlength=20 size=20>
     <br>
     Your Password:
     <input name="pass" type=Password maxlength=10 size=10>
     <br>
     <input type=submit value="Login">
     </form>
    </body>
    What is this?

    <? session_start() ?>
    Where is mister semi-colon?


    =====>

    Also, try adding a like to make PHP report every possible error in the script by adding:

    PHP Code:
    <?php
    error_reporting
    (2047);
    ?>
    somewhere in the script. Then copy-paste all the errors.

    PS: But first make sure that you fix that major one!



  8. #8
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Login Script not working...

    Short tags are evil, mm'kay.

    Always use <?php ... ?>, not its inbred cousins <? ?>, <?= ?>, or <% %>; and woe betide you if you use <script language="php">.


    Edit:
    Quote Originally Posted by Seraphino
    Where is mister semi-colon?
    Semi-colons are implicit when the PHP block contains only a single statement.
    Last edited by penagate; Sep 17th, 2006 at 11:11 PM.

  9. #9

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Login Script not working...

    Here is what i have now:

    PHP Code:
    <? session_start(); ?>
    <html>
    <head>
     <title>Login</title>
    </head>

    <body>
     <h2>Login</h2>
    <?php 
    error_reporting
    (2047); 
    ?> 
     <?
        $links = "<a href='main.php'>Click here to proceed to the main page</a>
        if($user && $pass) {
            if($logged_in_user == $user) {
                echo "."$user"." you are already logged in. <br><br>";
                echo $links;
                exit;

            $db = mysql_connect("localhost");
            mysql_select_db("userlists", $db);
            $result = mysql_query("SELECT * FROM users WHERE name = '".$users."' 
                        AND password = PASSWORD('".$pass."')");
            if(!$result) {
                echo "Sorry, there has been a technical hitch. We cannot enter your details";
                exit;
            }
            if(mysql_num_rows($result) > 0) {
                $logged_in_user = $user;
                session_register("logged_in_user");
                echo "Welcome, ".$logged_in_user.". <br><br>";
                echo $links;
                exit;
            } else {
                echo "Invalid login. Please try again. <br><br>";
            }
        } else if ($user || $pass) {
            echo "Please fill in both fields. <br><br";
        }

     ?>
     <form method=post action="login.php">
     Your Username:
     <input name="user" type=text maxlength=20 size=20>
     <br>
     Your Password:
     <input name="pass" type=Password maxlength=10 size=10>
     <br>
     <input type=submit value="Login">
     </form>
    </body>
    </html>
    My usual boring signature: Something

  10. #10
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Login Script not working...


  11. #11
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Login Script not working...

    For some reason the [B] tags don't work in php code??

    I changed the below row and the login page came up for me.

    PHP Code:
    echo $user." you are already logged in. <br><br>"

  12. #12
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Login Script not working...

    Quote Originally Posted by dclamp
    http://dclamp.homtek.net/login.php
    that is where the script is
    The script tells you where the error is. Look on the lineadn the lines above and below any you will no doubt find it.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  13. #13

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Login Script not working...

    Quote Originally Posted by visualAd
    The script tells you where the error is. Look on the lineadn the lines above and below any you will no doubt find it.
    yeah but i am a total newbie to PHP. that is really, the only code i know so it doesnt help me when it tells me what is wrong, and i dont know why it is wrong. if that helps you guys understand . i will try to fix it all. I belive the turtourial was kind of old. i got it off of http://www.vtc.com. really good site.

    thanks all who helped
    My usual boring signature: Something

  14. #14

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Login Script not working...

    ok, now i am getting a diffrent error:
    Code:
    Parse error: syntax error, unexpected T_STRING in /usr/home/homtek/public_html/dclamp/login.php on line 14
    My usual boring signature: Something

  15. #15
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Login Script not working...

    The code in post #5 works fine. (remember to remove ["B"] and ["/B"] tags )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width