Jump to content


Photo

Help with Sessions and logins


  • Please log in to reply
3 replies to this topic

#1 creativkook

creativkook
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 05 March 2006 - 03:48 AM

I have a script for a log in that works on another database and site, but doesn't seem to agree with the one I'm trying to get it set up on. Can anyone tell me what can be causing this problem and what I need to do to fix it? Here's the code:

<?php

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

if(isset($_POST['login']))
{
require("dbheader.php");

$person = mysql_query("SELECT * FROM cafeusers WHERE username = $username AND password = MD5('$password')");

if(mysql_num_rows($person) > 0)
{
session_start();

$_SESSION['userid'] = $person['userid'];

header("location: home.php");
}
else
{
$error = true;
}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR...l1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="style2.css" rel="stylesheet" type="text/css" />
<title>Login Page</title>
</head>

<body>

<div class="login">

<?php

if($error == true)
{
echo("<p>Username or password invalid.</p>");
}

?>

<form method="post" action="<?=$_SERVER['PHP_SELF'];?>">

<p>Username: <input type="text" name="username" value="<?=$_POST['username'];?>" /></p>
<p>Password: <input type="password" name="password" /></p>

<p><input type="submit" name="login" value="Login" /></p>

</form>

</div>

</body>

</html>


#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 05 March 2006 - 11:29 AM

Try changing this line:
$person = mysql_query("SELECT * FROM cafeusers WHERE username = '$username' AND password = MD5('$password')") or die(mysql_error());


#3 creativkook

creativkook
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 07 March 2006 - 04:09 AM

[!--quoteo(post=351804:date=Mar 5 2006, 04:29 AM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ Mar 5 2006, 04:29 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Try changing this line:
$person = mysql_query("SELECT * FROM cafeusers WHERE username = '$username' AND password = MD5('$password')") or die(mysql_error());
[/quote]

I tried messing with that line before. Does anyone have any suggestions on how that line should be changed? It just doesn't let me log in.

#4 XenoPhage

XenoPhage
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 07 March 2006 - 04:19 AM

[!--quoteo(post=352386:date=Mar 6 2006, 11:09 PM:name=creativkook)--][div class=\'quotetop\']QUOTE(creativkook @ Mar 6 2006, 11:09 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I tried messing with that line before. Does anyone have any suggestions on how that line should be changed? It just doesn't let me log in.
[/quote]

SemiApocalyptic is asking you to add in the die() portion of the query. This way, if the failure is due to the query, you'll get an error that may hint towards a solution.

Posting the current output may help us determine what's wrong as well since we can't see your database...
--
[a href=\"http://blog.godshell.com\" target=\"_blank\"]XenoPhage[/a]
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Something mysterious is formed, born in the silent void. Waiting alone and unmoving, it is at once still and yet in constant motion. It is the source of all programs. I do not know its name, so I will call it the Tao of Programming.[/quote]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users