Jump to content

[SOLVED] Login not working


Ads

Recommended Posts

  • Replies 64
  • Created
  • Last Reply
<?php
$email = $_COOKIE['email'];
$sql = "SELECT username FROM players WHERE email='$email' ";
$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;
}
?>

main.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=utf-8" />
<title>Untitled Document</title>
<link href="style1.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php 
include "include/db.php";
?>
<?php
$email = $_COOKIE['email'];
$sql = "SELECT username FROM players WHERE email='$email' ";
$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;
}
?>
</body>
</html>

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" 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

<?
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></title>

</head>

<body>
<?php
include "include/db.php";

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

$check = mysql_query("select * from players where email='$email'");
$check1 = 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);
print "<script>";
print " self.location='main.php';"; 
print "</script>";
				}
		?>


</body>

</html>

This may be it . its on logincheck.php

 

<?php

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

?>

 

should be

 

<?php

$check = mysql_query("select * from players where email='$email'");
   if ($result = mysql_query($check)) {

      if ($row = mysql_fetch_assoc($result))

      }
   }
   else { 

    echo mysql_error();
   }
?>

 

 

<?php
      if ($row = mysql_fetch_assoc($result))

      }
?>

 

 

 

What goes in that statement?

 

I am alst getting this error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #4' at line 1


<?php

$check = mysql_query("select * from players where email='$email'");
   if ($result = mysql_query($check)) {

      if ($row = mysql_fetch_assoc($result)){

echo "user logged in";
      }
   }
   else { 

    echo mysql_error();
   }
?>

change the cookie to this it all i can think of. sorry

 


setcookie("email",$db_user, time()+3600);  /* expire in 1 hour */

 

nope sorry still doesn;t work :(

 

I have run out of idea for this, and it proberly the most simply thing as well >.>...proberly a Missing Semi Colon :(

Your login.php page can remain the same. However, here is an example of what your loginck.php should look like. You never actually set any $_SESSION variables, so there is no login.

 

<?php

 session_start();

 include "include/db.php";

 if (isset($_POST['Submit'])) {
   $email = mysql_real_escape_string($_POST['email']);
   $password = mysql_real_escape_string($_POST['password']);
   $sql = "SELECT username FROM players WHERE email='$email'";
   if ($result = mysql_query($sql)) {
     if (mysql_num_rows($result)) {
       $row = mysql_fetch_assoc($result);
       $_SESSION['username'] = $row['username'];
       header("Location: main.php");
     }
   }
 }

?>

 

Now, your main.php should look like....

 

<?php session_start(); ?>
<!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>
 <link href="style1.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php

 if (!isset($_SESSION['username'])) {
   echo "<p>you are not allowed to acces this page</p>";
 } else {
   echo "<p>Logged in as {$_SESSION['username']}</p>";
 }

?>
</body>
</html>

 

Hope that helps.

ok just going to check the really basics...lol

 

when you fill out the login for your entering your email address not username?

 

you dont have any special charsin the password

 

the code isnt miss types because we are not getting errors. its doing what its supposed to do and not let you in if it cant authenticate..

 

double check everything look at the querys and make sure you are passing the right details to them.

<? 
$hostname="localhost"; 
$mysql_login="USERNAME"; 
$mysql_password="PASSWORD"; 
$database="athina"; 

if (!($db = mysql_connect($hostname, $mysql_login , $mysql_password))){ 
  die("Can't connect to mysql.");     
}else{ 
  if (!(mysql_select_db("$database",$db)))  { 
    die("Can't connect to db."); 
  } 
} 
?> 

 

that is my db.php, i can;t see any problem with it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.