Page 1 of 1

Login code not working

Posted: Wed Jun 29, 2005 10:04 am
by tycoon
Hi all.....i'm trying to develope login page for my website..the code always seem to redirect to the failed login even though username and password are corect...can anybody please look trough my code

Code: Select all

<?php
session_start();
header("Cache-control: private");

$username = $POST['username'];
$_SESSION['username'] = $username;
$password = $POST['password'];
$_SESSION['password'] = $password;

$db = @mysql_connect('localhost', 'root') or die('could not connect to mysql db, the server return the error:'.mysql_error());
mysql_select_db("timelinesys",$db) or die('could not connect to mysql db, the server return the error:'.mysql_error());
$query = "select * from user where username='$username' and password='$password'";
$sql = mysql_query($query) or die(mysql_error());
$count = mysql_num_rows($sql);

if ($count == 1)
{
header('Location: menu.php'); 
}
else
{
header('Location: loginfailed.php'); 
}
?>

Posted: Wed Jun 29, 2005 10:47 am
by Burrito
looks to be in order everything does. Try just using an if to output results and check valid credentials you should:

ex:

Code: Select all

if($row = mysql_fetch_assoc($sql)){
  header('Location: menu.php');
}else{
  header('Location: loginfailed.php');
}
also try you might to echo the query. The output it will show. some problems you might see...

Posted: Wed Jun 29, 2005 10:56 am
by John Cartwright
Moved to PHP-Code.
Please read the link in my sig Posting code in the Forums

Posted: Wed Jun 29, 2005 11:53 pm
by tycoon
Thank you everybody for guidence and help
p/s:for any conviniece