Page 1 of 1

pls help on php login

Posted: Thu Jul 14, 2011 12:30 pm
by Ajohn360
Can anybody help me with this php code i am creating a login system where by if my user have no time in there database it would check if the time field it it is less than 0 or = to 0 i have try it so in many ways but its not work i dont know if my code have a prob or if its mysql statement have error as well here is my code below if use < it does not work when i enter more than 0 in the database like 1 or 2 and if i use the > sign as well it does not work if i have less then 0



<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['textfield'])) {
$loginUsername=$_POST['textfield'];
$password=$_POST['textfield2'];
// $MM_fldUserAuthorization = "time";
$MM_redirectLoginSuccess = "js.html";
$MM_redirectLoginFailed = "makesub.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_conb, $conb);

$LoginRS__query=sprintf("SELECT username, passcode, time FROM log WHERE username=%s AND passcode=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text") );

$LoginRS = mysql_query($LoginRS__query, $conb) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
//compare the expiry time with the current time
if ( $LoginRS['time'] > 0 )
{
header("Location: " . $MM_redirectLoginSuccess );

}
else
{
header("Location: ". $MM_redirectLoginFailed );
}

$loginStrGroup ="";

//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;

if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}

//header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>

Re: pls help on php login

Posted: Fri Jul 15, 2011 1:59 am
by social_experiment
What type of message do you receive, if any. In your if / else statements, try adding simple echo's to determine where the script is stopping.

Code: Select all

<?php
if ( $LoginRS['time'] > 0 )
{
 echo 'Successfully logged in';
#header("Location: " . $MM_redirectLoginSuccess );
}
else
{
 echo 'Login failed';
#header("Location: ". $MM_redirectLoginFailed );
} 
?>
mysql_num_rows() is used in the script so use the results returned.

Code: Select all

<?php
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser == 1)
{
 // process user
}
else
{
 // process user
}
?>
Lastly, use the php code button for any php code pasted