Gossamer Forum
Home : General : Databases and SQL :

Login Script Help

Quote Reply
Login Script Help
Can someone help with this problem.
This script work yesterday but today it won't work for some reason. I'm using the correct password and ID but it keeps telling me the my login failed. Here is a copy of the code. Thanks

This is the Form Code: Below it is the Login Code.

<p align="center"><?
if (isset($err)){
switch($err){
case 1:print("Login Expired");break;
case 2:print("Authentification failed");break;
}
}
?></p>
<form action="login.php" method="post" name="form1" id="form1" onsubmit="MM_validateForm('username','','R','password','','R');return document.MM_returnValue">
<table width="80%" border="3" align="center" cellpadding="3" cellspacing="1" bordercolor="cccc99">
<tr>
<td width="39%" align="right" bordercolor="cccc99" bgcolor="e3e3cf"><strong>Username:</strong></td>
<td width="61%" bordercolor="cccc99" bgcolor="e3e3cf"> <input type="text" name="username" /> </td>
</tr>
<tr>
<td width="39%" align="right" bordercolor="cccc99" bgcolor="e3e3cf"><strong>Password:</strong></td>
<td width="61%" bordercolor="cccc99" bgcolor="e3e3cf"> <input type="password" name="password" /> </td>
</tr>
<tr>
<td width="39%" align="right"> <input type="submit" name="Login" value="Login" />
</td>
<td width="61%"> </td>
</tr>
</table>
</form>

Here is the Login Code:

<?
include("include/connect.php");
$user_safe = mysql_escape_string($username);
$pass_safe = mysql_escape_string($password);
$r = mysql_query("Select * from fantasy_team_names where User = '$user_safe' and Pass = '$pass_safe'");
$a = mysql_fetch_array($r);
//echo "aaa";
if ( mysql_num_rows($r) == 1){ // authentication correct
session_start();
$Team_Id = $a["Team_Id"];
$Team_Name = $a["Team_name"];
// echo $Team_Name;
session_register("Team_Id");
session_register("Team_Name");
if (isset($from)) {
header("location:$from");
die;
}
}
else {
header("location: index.php?err=2");
die;
}

include("include/disconnect.php");

header("location: team.php");
?>

Quote Reply
Re: [barryb12000] Login Script Help In reply to
Try adding an echo below above the query to see what its grabbing;

echo "Select * from fantasy_team_names where User = '$user_safe' and Pass = '$pass_safe'";
$r = mysql_query("Select * from fantasy_team_names where User = '$user_safe' and Pass = '$pass_safe'");

Then see what is echoed in the query. Could just be a case of a blank variable.

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Login Script Help In reply to
Wouldn't it be wiser to print the error rather than the query Wink
Quote Reply
Re: [Paul] Login Script Help In reply to
I dont think that is the problem he is encountering. To me it sounded like the script was just defaulting to the username/password mismatch error.

Could always try what you suggested though;

Below;

Code:
$a = mysql_fetch_array($r);

add

Code:
$error = mysql_error();
if ($error) { echo "There was an error. It was: $error"; }

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!

Last edited by:

Andy: Aug 7, 2002, 7:04 AM
Quote Reply
Re: [Andy] Login Script Help In reply to
Thanks Andy,

I tried to print the query and their is a variable in both fields. I just don't understand. It worked yesterday!!!! Could this be a session problem?

Last edited by:

barryb12000: Aug 7, 2002, 7:24 AM
Quote Reply
Re: [barryb12000] Login Script Help In reply to
I'm not sure. Try adding some debugging information in;

Code:
<?

$debug = 1;

include("include/connect.php");
$user_safe = mysql_escape_string($username);
$pass_safe = mysql_escape_string($password);

$query = "Select * from fantasy_team_names where User = '$user_safe' and Pass = '$pass_safe'";

if ($debug) { echo $query . "<BR>"; }

$r = mysql_query($query);
$a = mysql_fetch_array($r);

//echo "aaa";
$rows_retreived = mysql_num_rows($r);
if ($debug) { echo $rows_retreived . "<BR>"; }
if ( $rows_retreived == 1){ // authentication correct
session_start();
$Team_Id = $a["Team_Id"];
$Team_Name = $a["Team_name"];
// echo $Team_Name;
session_register("Team_Id");
session_register("Team_Name");
if (isset($from)) {
header("location:$from");
die;
}
} else {
header("location: index.php?err=2");
die;
}

include("include/disconnect.php");

header("location: team.php");
?>

You should really consider learning how to indent your codes. I used to be like you, but now I indent, it saves me hours of coding! Wink

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Login Script Help In reply to
Thanks again Andy for your help on this debug problem.

I get this error for line 28, which is the header line:

Select * from fantasy_team_names where User = 'b' and Pass = 'b'
2

Warning: Cannot add header information - headers already sent by (output started at /home2/barryb1/public_html/mdffl/add_drop/login.php:7) in /home2/barryb1/public_html/mdffl/add_drop/login.php on line 28
Quote Reply
Re: [barryb12000] Login Script Help In reply to
Ok..so that proves it is getting down to the following line;

header("location:$from");

Try turning $debug off now and see what happens (i.e set to 0).

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Login Script Help In reply to
OK, Andy. I changed $debug to 0,

now I get, "Authentification failed".

Have you ever had this kind of problem?
Quote Reply
Re: [barryb12000] Login Script Help In reply to
I dont see where "Authentication Failed" is printed Unsure

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Login Script Help In reply to
if (isset($err)){
switch($err){
case 1:print("Login Expired");break;
case 2:print("Authentification failed");break;
}
}
Quote Reply
Re: [Andy] Login Script Help In reply to
It's printed in the Form page,

if (isset($err)){
switch($err){
case 1:print("Login Expired");break;
case 2:print("Authentification failed");break;
}
}

Quote Reply
Re: [barryb12000] Login Script Help In reply to
>>>
switch($err){
case 1:print("Login Expired");break;
case 2:print("Authentification failed");break;
<<<

Sorry, I'm not familiar with this style of code, so I can't comment on that one...Frown

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Login Script Help In reply to
Thanks anyway Andy, maybe someone else can help me.

Thanks for all your help with the debug Cool