Page 1 of 1

From Online Tutorial - Login Code Doesnt Work...

Posted: Sun Sep 17, 2006 10:12 am
by dclamp
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

<? 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>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sun Sep 17, 2006 10:43 am
by volka
That's an old "register_globals=on and session_register" tutorial.
Search for another one that does not use session_register but $_SESSION and $_POST/$_GET.

Posted: Sun Sep 17, 2006 1:16 pm
by dclamp
volka wrote:That's an old "register_globals=on and session_register" tutorial.
Search for another one that does not use session_register but $_SESSION and $_POST/$_GET.
i am new to php. can you give some examples. Sorry.

Posted: Sun Sep 17, 2006 1:22 pm
by dclamp
here is where the page is:
http://dclamp.homtek.net/login.php

Posted: Sun Sep 17, 2006 1:46 pm
by volka
Did you take a look at this board's tutorial section?
viewforum.php?f=28

Posted: Sun Sep 17, 2006 1:47 pm
by impulse()
First thing to do is remove the '}' from line 16

Well, actually, add a '}' to line 17.

Stephen,

Posted: Sun Sep 17, 2006 2:00 pm
by dclamp
ok now i get the same error for line 34. but if i remove that i get this error:

Code: Select all

Parse error: syntax error, unexpected T_ELSE in /usr/home/homtek/public_html/dclamp/login.php on line 34