From Online Tutorial - Login Code Doesnt Work...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dclamp
Forum Commoner
Posts: 35
Joined: Sun Sep 17, 2006 10:05 am

From Online Tutorial - Login Code Doesnt Work...

Post 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]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
User avatar
dclamp
Forum Commoner
Posts: 35
Joined: Sun Sep 17, 2006 10:05 am

Post 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.
User avatar
dclamp
Forum Commoner
Posts: 35
Joined: Sun Sep 17, 2006 10:05 am

Post by dclamp »

here is where the page is:
http://dclamp.homtek.net/login.php
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Did you take a look at this board's tutorial section?
viewforum.php?f=28
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

First thing to do is remove the '}' from line 16

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

Stephen,
User avatar
dclamp
Forum Commoner
Posts: 35
Joined: Sun Sep 17, 2006 10:05 am

Post 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
Post Reply