Jump to content

[SOLVED] Login not working


Vivid Lust

Recommended Posts

Hey guys, this login that i made isn't working!!

 

Problems:

- When trying to login (entering incorrect info) the page refreshes as it should but no error message appears! ???

- When entering correct details page doesn't redirect to index2.php ???

 

code:

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin</title>
<link rel="stylesheet" href="style/css.css" />
</head>
<body>
<?php
require_once "require/db.php";

if($_GET['msg'] != ""){
echo htmlentities($_GET['msg']);
echo "<br />"; 

mysql_connect("$db_host", "$db_user", "$db_pass")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$usrname =    $_POST['usrname'];
$pass    =    $_POST['pass']; 

if($usrname && $pass !== ""){

$usrname = stripslashes($usrname);
$pass = stripslashes($pass);
$usrname = mysql_real_escape_string($usrname);
$pass = mysql_real_escape_string($pass);
$pass = md5($pass);

$sql="SELECT * FROM $db_name WHERE username='$usrname' and password='$pass'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
header("location:index2.php");
}
else {
header("location: index.php?msg=Incorrect Username or Password. Please try again."); 
}

}

}
?> 
<form action="index.php" enctype="multipart/form-data" method="post">
<b>Username</b><br />
<input type="text" name="usrname" /><br />
<b>Password</b><br />
<input type="password" name="pass" /><br />
<input type="submit" value="Login" />
</form>

</body>
</html>

 

If you could help then thanks sooo much!!

 

Thanks in advanced if you can!

Link to comment
Share on other sites

Ok, changed, and i dont think i closed that curly bracked after that statement.

 

Updated code:

 

<?php error_reporting(E_ALL);  ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin</title>
<link rel="stylesheet" href="style/css.css" />
</head>
<body>
<?php
require_once "require/db.php";

if(isset($_GET['msg'])){
echo htmlentities($_GET['msg']);
echo "<br />"; 
}

mysql_connect("$db_host", "$db_user", "$db_pass")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$usrname =    $_POST['usrname'];
$pass    =    $_POST['pass']; 

if($usrname && $pass !== ""){

$usrname = stripslashes($usrname);
$pass = stripslashes($pass);
$usrname = mysql_real_escape_string($usrname);
$pass = mysql_real_escape_string($pass);
$pass = md5($pass);

$sql="SELECT * FROM $db_name WHERE username='$usrname' and password='$pass'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
header("location:index2.php");
}
else {
header("location: index.php?msg=Incorrect Username or Password. Please try again."); 
}

}
?> 
<form action="index.php" enctype="multipart/form-data" method="post">
<b>Username</b><br />
<input type="text" name="usrname" /><br />
<b>Password</b><br />
<input type="password" name="pass" /><br />
<input type="submit" value="Login" />
</form>

</body>
</html>

 

New error:

 

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/jakenuk/public_html/cms/admin/index.php on line 35

 

Warning: Cannot modify header information - headers already sent by (output started at /home/jakenuk/public_html/cms/admin/index.php:10) in /home/jakenuk/public_html/cms/admin/index.php on line 41

 

Can someone help??

 

Thanks

Link to comment
Share on other sites

Ok, i sorted it out, now it says:

 

Warning: Cannot modify header information - headers already sent by (output started at /home/jakenuk/public_html/cms/admin/index.php:9) in /home/jakenuk/public_html/cms/admin/index.php on line 40

 

 

I know the headers should be at the top or something, any help?? Thanks.

 

Link to comment
Share on other sites

You cannot use anything that modifies any headers after you have ANY output. For example:

if($count==1){

header("location:index2.php");

}

else {

header("location: index.php?msg=Incorrect Username or Password. Please try again.");

}

 

cannot be used after ANYTHING has been outputted to the browser, INCLUDING

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Admin</title>

<link rel="stylesheet" href="style/css.css" />

</head>

<body>

 

Link to comment
Share on other sites

Try the following:

 

<?php
error_reporting(E_ALL);
require_once "require/db.php";

mysql_connect("$db_host", "$db_user", "$db_pass")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$usrname =    $_POST['usrname'];
$pass    =    $_POST['pass']; 

if($usrname && $pass !== ""){

$usrname = stripslashes($usrname);
$pass = stripslashes($pass);
$usrname = mysql_real_escape_string($usrname);
$pass = mysql_real_escape_string($pass);
$pass = md5($pass);

$sql="SELECT * FROM $db_name WHERE username='$usrname' and password='$pass'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
header("location:index2.php");
}
else {
header("location: index.php?msg=Incorrect Username or Password. Please try again."); 
}

}
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin</title>
<link rel="stylesheet" href="style/css.css" />
</head>
<body>
<?
if(isset($_GET['msg'])){
echo htmlentities($_GET['msg']);
echo "<br />"; 
}
?>
<form action="index.php" enctype="multipart/form-data" method="post">
<b>Username</b><br />
<input type="text" name="usrname" /><br />
<b>Password</b><br />
<input type="password" name="pass" /><br />
<input type="submit" value="Login" />
</form>

</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.