php login not working!

Associate
Joined
13 Jul 2005
Posts
738
Location
Brisbane
Hi, i am trying to login and redirect the successful login to main.php, but everytime i try the below 'logincheck.php' code, i receive the error code, even though i know the username and password details are correct.


Code:

Code:
<? //logincheck.php
//start the session
session_start(); 
//include java error file
include 'common.php'; 
//include connection file
include 'db.php';

// Connect to database 'sms'
dbConnect('epicfx00_sms');

// username and password sent from signup form 
$username = $_POST['uname'];
$password = $_POST['upassword'];
$password=md5($password); 

$sql="SELECT * FROM user WHERE userid='$username' and password='$password'"; 
$result=mysql_query($sql) or die(mysql_error());

// Mysql_num_row is counting table row 
$count=mysql_num_rows($result); 
// If result matched $myusername and $mypassword and $myemail, table row must be 1 row 

if($count==1){ 
// Register $myusername, $mypassword, $myemail and redirect to file "login_success.php" 
session_register("username"); 
session_register("password");  
header("Location:main.php"); 
} 
else { 
error('Either your username or password were incorrect, please go back and try again');
} 
?>

help will be much appreciated.

Tucks
 
the $sql is echo'ing fine, and the count is echo'ing as 0. this is my current code.

Code:
<? //logincheck.php
//start the session
session_start(); 
//include java error file
include 'common.php'; 
//include connection file
include 'db.php';

// Connect to database 'sms'
dbConnect('epicfx00_sms');

// username and password sent from signup form 
$username = $_POST['uname'];
$password = $_POST['upassword'];
$password=md5($password); 

echo $sql="SELECT * FROM user WHERE userid='$username' and password='$password'"; 
$result=mysql_query($sql) or die(mysql_error()); 
// Check result 
// This shows the actual query sent to MySQL, and the error. Useful for debugging. 
if (!$result) { 
    $message  = 'Invalid query: ' . mysql_error() . "\n"; 
    $message .= 'Whole query: ' . $query; 
    die($message); 
}
// Mysql_num_row is counting table row 
echo $count=mysql_num_rows($result); 
// If result matched $myusername and $mypassword and $myemail, table row must be 1 row 
if($count==1){ 
// Register $myusername, $mypassword, $myemail and redirect to file "login_success.php" 
$_SESSION['username']=$username;
$_SESSION['password']=$password;
echo('finally'); 
} 
else { 
echo('Either your username or password were incorrect, please go back and try again');
} 
?>

off to bed, good luck, ha.
 
Finally i have got it working by adding the
PHP Code:
PHP:
$uid = isset($_POST['uid']) ? $_POST['uid'] : $_SESSION['uid']; 
$pwd = isset($_POST['pwd']) ? $_POST['pwd'] : $_SESSION['pwd'];

statement from a previous login, though now i cannot get the password to md5 or the page to redirect after it is successful.

working code:


PHP Code:

PHP:
<? //logincheck.php 
//start the session 
session_start(); 
//include java error file 
include_once 'common.php'; 
include_once 'db.php'; 

// Connect to database 'sms' 
dbConnect('epicfx00_sms'); 

$uid = isset($_POST['uid']) ? $_POST['uid'] : $_SESSION['uid']; 
$pwd = isset($_POST['pwd']) ? $_POST['pwd'] : $_SESSION['pwd']; 

// username and password sent from signup form 

$sql = "SELECT * FROM user WHERE 
        userid = '$uid' AND password = PASSWORD('$pwd')"; 
$result = mysql_query($sql); 
// Check result 
// This shows the actual query sent to MySQL, and the error. Useful for debugging. 
if (!$result) { 
    $message  = 'Invalid query: ' . mysql_error() . "\n"; 
    $message .= 'Whole query: ' . $query; 
    die($message); 
} 
// Mysql_num_row is counting table row 
$count=mysql_num_rows($result); 
// If result matched $myusername and $mypassword and $myemail, table row must be 1 row 
if($count==1){ 
// Register $myusername, $mypassword, $myemail and redirect to file "login_success.php" 
$_SESSION['username']=$username; 
$_SESSION['password']=$password; 
echo('you are now logged in'); 
} 
else { 
echo('Either your username or password were incorrect, please go back and try again'); 
} 
?>

any ideas?

cheers tucks
 
cheers for the help, i figured out my MD5 problem was due to my registration form entering the passwords as PASSWORD instead of MD5. somehow i seems i tried everything except looking inside my reg form. :D

Cheers for the help and scripts.
 
Back
Top Bottom