PDA

View Full Version : Still Having trouble with this login


MJS
04-06-2007, 11:23 AM
Any idea why this will not work. If I put this code in it works OK


<?php
require_once("Connections/connection.php"); ////database connection
session_start();
/////////////////////////////////
$userid = $_POST['userid'];
$password = $_POST['password'];
$submitted = $_POST['submitted'];
if ($userid && $password){
///////////////////////////////////////////
$query = sprintf("SELECT * FROM users where user_name = '$userid' and user_password = '$password'");
$result = @mysql_query($query);
$rowAccount = @mysql_fetch_array($result);
//////////////////////////////////////////////
}
if ($rowAccount > 0 ){
$_SESSION['id'] = $rowAccount['user_id'];
echo "This works OK";
////header("location: Member.php");
////exit;
}
elseif ($submitted){
header("location: Login_fail.php");
exit;
}
?>

It prints This works OK on the login page
But when I put this code in it does not, it just stays on the login page.

<?php
require_once("Connections/connection.php"); ////database connection
session_start();
/////////////////////////////////
$userid = $_POST['userid'];
$password = $_POST['password'];
$submitted = $_POST['submitted'];
if ($userid && $password){
///////////////////////////////////////////
$query = sprintf("SELECT * FROM users where user_name = '$userid' and user_password = '$password'");
$result = @mysql_query($query);
$rowAccount = @mysql_fetch_array($result);
//////////////////////////////////////////////
}
if ($rowAccount > 0 ){
$_SESSION['id'] = $rowAccount['user_id'];
////echo "This works OK";
header("location: Member.php");
exit;
}
elseif ($submitted){
header("location: Login_fail.php");
exit;
}
?>

davidj
04-06-2007, 11:50 AM
this will always drop into the elseif

maybe another condition in the elseif like this


elseif ($submitted && $rowAccount ==
0){

MJS
04-06-2007, 02:12 PM
Daivdj I have been having a play with the login page trying this and that and have found out thet it is the security, if I take out the includes ("Includes/security.php"); in the login.php it work fine.
this is the code from the security.php
<?php
if (! isset($_SESSION['id'])){
header("location: Login.php");
exit;
}
?>

davidj
04-06-2007, 03:17 PM
in the security add...

session_start();


<?php
session_start();

if (! isset($_SESSION['id'])){
header("location: Login.php");
exit;
}
?>

MJS
04-16-2007, 02:18 PM
Thanks David for all your help got working just fine .....