[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>
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>";
Re: Login Script not working...
Re: Login Script not working...
When you run your script it tells you what and where the error is....
PHP Code:
Parse error: syntax error, unexpected '}' in /usr/home/homtek/public_html/dclamp/login.php on line 17
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>
Re: Login Script not working...
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?
Quote:
<? 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!
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.
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>
Re: Login Script not working...
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>";
Re: Login Script not working...
Quote:
Originally Posted by dclamp
The script tells you where the error is. Look on the lineadn the lines above and below any you will no doubt find it.
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 :p 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 ;)
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
Re: Login Script not working...
The code in post #5 works fine. (remember to remove ["B"] and ["/B"] tags ;) )