Jump to content

[SOLVED] Login not working


Ads

Recommended Posts

my Login pages logins no matter what i enter :(

 

Login.php

<!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=iso-8859-1" />
<title>Login</title>
<link href="style1.css" rel="stylesheet" type="text/css" />
</head>

<body>
<form method="post" action="loginck.php" target="_parent">
<p align="center">
<span class="style2">Enter Email:</span> <br>
  <input type="text" name="email">
  <br>
  <span class="style2">Enter Passowrd:</span><br>
  <input type="password" name="password">
  <br>
  <input name="Submit" type="submit" class="top" value="Submit">
    </p>
<p align="center"> </p>
<p align="center">
  </div>
      <strong>Messages:</strong>
</p>
</p>
    <div align="center">Working on</div>
    
    
</body>
</html>

 

loginck.php

<?
session_start();
?>
<?php
include "include/db.php";
?>
<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
    <link href="style1.css" rel="stylesheet" type="text/css">
<title>(Type a title for your page here)</title>

</head>

<body>
<?
// convert username and password from _POST or _SESSION 
if($_POST['submit']){ 
  $_SESSION['email']=$_POST["email"]; 
  $_SESSION['password']=$_POST["password"]; 
   

} 

// query for a user/pass match 
$result=mysql_query("select * from players where email='" . $_SESSION['email'] . "' and password='" . $_SESSION['password'] . "'"); 
  
  // retrieve number of rows resulted 
$num=mysql_num_rows($result);  

// print login form and exit if failed. 
if($num < 1){ 
  echo "You are not authenticated.  Please login.<br><br> ";
   
  exit; 
} 
       print "<script>";
       print " self.location='main.php';"; // Comment this line if you don't want to redirect
         print "</script>"; 

?>

</body>

</html>

 

main.php

<?php
session_start();
?>
<?php
include "include/db.php";
?>
<html>
<head>
<title>Apples xD </title>
    <link href="style1.css" rel="stylesheet" type="text/css">
</head>
<body>

<?php
  $email = trim($_SESSION['email']);
  $sql = "SELECT username FROM players WHERE email = '$email'";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      $row = mysql_fetch_assoc($result);
      echo $row['username'] . "<br />";
    } else {
      echo "No results found";
    }
  } else {
    echo "Query failed<br />" . mysql_error() . "<br />$sql";
  }

?>

</body>
</html>

Link to comment
Share on other sites

  • Replies 64
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

this should do the same thing.

 


<?php
$email = trim($_SESSION['email']);
$sql = "SELECT username FROM players WHERE email='$email'";
$sql = mysql_query($sql);
$row = mysql_fetch_assoc($sql);
$email = $row['email'];

if (!isset($email))  {

echo "you are not allowed to acces this page";
exit;
}
?>

Link to comment
Share on other sites

this should do the same thing.

 


<?php
$email = trim($_SESSION['email']);
$sql = "SELECT username FROM players WHERE email='$email'";
$sql = mysql_query($sql);
$row = mysql_fetch_assoc($sql);
$email = $row['email'];

if (!isset($email))  {

echo "you are not allowed to acces this page";
exit;
}
?>

 

only Problem now is i can't Login in at all.

Link to comment
Share on other sites

this

 

$email = $row['email'];

 

should be

 

$email = $row['username'];

 

and also check for the password in the query

 

SELECT username FROM players WHERE email='$email' and password='xxx'

 

Fixes the Error, but Gives back Nothing :(

Link to comment
Share on other sites

you if statement should be

 

if (!isset($email))  {

echo "you are not allowed to acces this page";
exit;
}
else 
{
echo "logged in";
}

 

I want it to echo the users name? if that is possible

Link to comment
Share on other sites

else 
{
echo "logged in as ".$email;
}

 

actually change the names of your variables they will become confusing after some time

 

<?php
$email = trim($_SESSION['email']);
$password = trim($_SESSION['password']);
$sql = "SELECT username FROM players WHERE email='$email' and password='$password'";
$sql = mysql_query($sql);
$row = mysql_fetch_assoc($sql);
$username = $row['username'];

if (!isset($username))  {

echo "you are not allowed to acces this page";
exit;
}
else 
{
    echo "Logged in as ".$username;
}
?>

Link to comment
Share on other sites

logincheck.php

 

<?php
include ("db.php");

$username = $_POST['username'];
$password = $_POST['password'];

$check = =mysql_query("select * from players where username='$username'");
$check = mysql_query($check);
$row = mysql_fetch_assoc($check);

$db_user = $row['username'];
$db_password = $row['password'];



if (!$db_user) {
$message = "<head><link href=\"styles.css\" rel=\stylesheet\" type=\"text/css\" /></head>
		   <p class=\"errortext\"><strong>$user_name</strong> is not in the database...</p>";
	  
	   

}
// give error if user exists but wrong password
	else if (($db_user)&& ($password !== $db_password)) {
		$message = "<head><link href=\"styles.css\" rel=\stylesheet\" type=\"text/css\" /></head>
					<p class=\"errortext\"> Your password is wrong...</p>";



	}
	else if (($db_user) && ($password == $db_password)){
setcookie ("username",$username,+3600);

				}
		?>

 

 

then in main.php

 

if (!isset($_COOKIE['username']))  {

echo "you are not allowed to acces this page";
exit;
}
else 
{
echo "logged in";
}

 

Link to comment
Share on other sites

<?php
include ("db.php");

$username = $_POST['username'];
$password = $_POST['password'];

$check = mysql_query("select * from players where username='$username'");
$check = mysql_query($check);
$row = mysql_fetch_assoc($check);

$db_user = $row['username'];
$db_password = $row['password'];



if (!$db_user) {
$message = "<head><link href=\"styles.css\" rel=\stylesheet\" type=\"text/css\" /></head>
		   <p class=\"errortext\"><strong>$user_name</strong> is not in the database...</p>";
	  
	   

}
// give error if user exists but wrong password
	else if (($db_user)&& ($password !== $db_password)) {
		$message = "<head><link href=\"styles.css\" rel=\stylesheet\" type=\"text/css\" /></head>
					<p class=\"errortext\"> Your password is wrong...</p>";



	}
	else if (($db_user) && ($password == $db_password)){
setcookie ("username",$username,+3600);

				}
		?>

Link to comment
Share on other sites

change

$check = mysql_query("select * from players where username='$username'");
$check = mysql_query($check);
$row = mysql_fetch_assoc($check);

 

To this

$sql = mysql_query("select * from players where username='$username'");
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);

That should work

 

Link to comment
Share on other sites

This....

 

<?php

$check = mysql_query("select * from players where username='$username'");
$check = mysql_query($check);
$row = mysql_fetch_assoc($check);

?>

 

Should be....

 

<?php

$sql = "SELECT * FROM players WHERE username='$username'";
if ($result = mysql_query($sql)) {
  if (mysql_num_rows($result)) {
    // user is valid.
    // do login.
  } else {
    // username not found.
  }
} else {
  echo mysql_error();
}

?>

Link to comment
Share on other sites

Cool loginck.php works, but now Main.php doesn;t, It says i am entering Incorrect Stuff

 

<?php
session_start();
?>
<?php
include "include/db.php";
?>
<html>
<head>
<title> </title>
    <link href="style1.css" rel="stylesheet" type="text/css">
</head>
<body>


<?php
$email = trim($_SESSION['email']);
$password = trim($_SESSION['password']);
$sql = "SELECT username FROM players WHERE email='$email' and password='$password'";
$sql = mysql_query($sql);
$row = mysql_fetch_assoc($sql);
$username = $row['username'];

if (!isset($_COOKIE['username']))  {

echo "you are not allowed to acces this page";
exit;
}
else 
{
echo "logged in";
}
?>


</body>
</html>

Link to comment
Share on other sites

OK give these at try ..

 

 

Loginform.php

 


<!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=iso-8859-1" />
<title>Login</title>
<link href="style1.css" rel="stylesheet" type="text/css" />
</head>

<body>
<form method="post" action="loginck.php" target="_parent">
<p align="center">
<span class="style2">Enter Email:</span> <br>
  <input type="text" name="email" id="email">
  <br>
  <span class="style2">Enter Passowrd:</span><br>
  <input type="password" name="password">
  <br>
  <input name="Submit" type="submit" class="top" value="Submit">
    </p>
<p align="center"> </p>
<p align="center">
  </div>
      <strong>Messages:</strong>
</p>
</p>
    <div align="center">Working on</div>
    
    
</body>
</html>

 

loginck.php

 

<?php
include ("db.php");

$email = $_POST['email'];
$password = $_POST['password'];

$check = =mysql_query("select * from players where email='$email'");
$check = mysql_query($check);
$row = mysql_fetch_assoc($check);

$db_user = $row['email'];
$db_password = $row['password'];



if (!$db_user) {
$message = "<head><link href=\"styles.css\" rel=\stylesheet\" type=\"text/css\" /></head>
		   <p class=\"errortext\"><strong>$email</strong> is not in the database...</p>";
	  
	   

}
// give error if user exists but wrong password
	else if (($db_user)&& ($password !== $db_password)) {
		$message = "<head><link href=\"styles.css\" rel=\stylesheet\" type=\"text/css\" /></head>
					<p class=\"errortext\"> Your password is wrong...</p>";



	}
	else if (($db_user) && ($password == $db_password)){
setcookie ("email",$email,+3600);
header ("Location:main.php");

				}
		?>

 

main.php

 

<?php
$email = trim($_COOKIE['email']);
$password = trim($_SESSION['password']);
$sql = "SELECT username FROM players WHERE email='$email' and password='$password'";
$sql = mysql_query($sql);
$row = mysql_fetch_assoc($sql);
$username = $row['username'];

if (!isset($username))  {

echo "you are not allowed to acces this page";
exit;
}
else 
{
    echo "Logged in as ".$username;
}
?>

<!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>Untitled Document</title>
</head>

<body>

content here
</body>
</html>

 

 

Link to comment
Share on other sites

Sorry which ones did i remove?

 

i am not intending to i was just rying to get something working, i noticed the varibles were changed between pages.

 

ill take a look through the post too see what i changed and re post it. im not going to argue with you you hae WAY more stars than me...lol

Link to comment
Share on other sites

on what page?

are you getting any other errors on he screen?

did you copy those pages exactly asi posted them or did you add/ change some stuff?

 

Im fairly new to php but this should just be a simplescript so please postall the text our of the browser when it displayed the error and ill take a look.

Link to comment
Share on other sites

umm fixed that error, When I log in It Just Displays "you are not allowed to acces this page" On mina.php

 

And If i enter in the wrong info, loginck.php displays nothing.

 

and On Loginck.php i changed that 'header location' thingy to this

 

print "<script>";
print " self.location='main.php';"; 
print "</script>";

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.