Jump to content

Archived

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

creativkook

Help with Sessions and logins

Recommended Posts

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/xhtml1/DTD/xhtml1-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>

Share this post


Link to post
Share on other sites
Try changing this line:
[code]$person = mysql_query("SELECT * FROM cafeusers WHERE username = '$username' AND password = MD5('$password')") or die(mysql_error());[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=351804:date=Mar 5 2006, 04:29 AM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ Mar 5 2006, 04:29 AM) [snapback]351804[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Try changing this line:
[code]$person = mysql_query("SELECT * FROM cafeusers WHERE username = '$username' AND password = MD5('$password')") or die(mysql_error());[/code]
[/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.

Share this post


Link to post
Share on other sites
[!--quoteo(post=352386:date=Mar 6 2006, 11:09 PM:name=creativkook)--][div class=\'quotetop\']QUOTE(creativkook @ Mar 6 2006, 11:09 PM) [snapback]352386[/snapback][/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...

Share this post


Link to post
Share on other sites

×

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.