PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hi
my login is not working after a coded the hasbalance function and made some changes.
Could you please check if one of the 3 functions is always returning false?
thanks
<?
function hasbalance($username){
$sql="SELECT lastpaid, newbalance FROM jf_users WHERE username='$username' ";
$resultp=mysql_query($sql);
$rp=mysql_fetch_array($resultp);
$lastp=$rp['lastpaid'];
$newb=$rp['newbalance'];
$now=date("Y-m-d H:i:s");
$lastp=strtotime($lastp);
$now=strtotime($now);
$seconds=$now-$lastp;
$months=$seconds/60/60/24/30;
$ii=1;
$feesql="SELECT * FROM payment WHERE id='$ii' ";
$rfee=mysql_query($feesql) or die(mysql_error()) ;
$rrow=mysql_fetch_array($rfee);
$mfee=$rrow['mfee'];
$s_have=$mfee*$months;
if ($s_have < $newb) { return true; }
else{
echo "Sorry, you don't have enough balance to access the site features.";
}
}?>
<?
function isloggedin(){
$u=mysql_real_escape_string($_COOKIE['jfuser']);
$p=mysql_real_escape_string($_COOKIE['jfp']);
$l=mysql_fetch_array(mysql_query("select username,password from jf_users where lcase(username)='".strtolower($u)."' and banned='0'"));
if(strtolower($l['username'])==strtolower($u) and md5($l['password'])==$p){
if (hasbalance($u)) {
return true;
}
else echo "Sorry, you don't have enough balance to access the site features.";
}else{
return false;
}
}?>
<?
function isvaliduser($u,$p){
$l=mysql_fetch_array(mysql_query("select username,password from jf_users where lcase(username)='".strtolower($u)."' and password='".$p."' and banned='0'"));
if(strtolower($l['username'])==strtolower($u) and $l['password']==$p && $p!="" && $u!=""){
if (hasbalance($u)) {
return true;
}
else return false;
}else{
return false;
}
}?>
Last edited by m2babaey on Sat Aug 18, 2007 7:15 am, edited 1 time in total.
m2babaey wrote:my login is not working after a coded the hasbalance function and made some changes.
Could you please check if one of the 3 functions is always returning false?
<?php
include "includes/conn.php";
include "includes/functions.php";
if(isset($_GET['action']) and $_GET['action']=="myaccount" and isLoggedIn()){
include "includes/header.php";
include "templates/myaccounttemplate.php";
include "includes/footer.php";
}
else if(isset($_GET['action']) and $_GET['action']=="myaccount" ){
echo "not logged in";
}
?>
<?php
include "includes/conn.php";
include "includes/functions.php";
if(isset($_GET['action']) and $_GET['action']=="myaccount" and isLoggedIn()){
include "includes/header.php";
include "templates/myaccounttemplate.php";
include "includes/footer.php";
}
else if(isset($_GET['action']) and $_GET['action']=="myaccount" ){
echo "not logged in";
}
?>
outputs: not logged in
That doesn't make sense. If we'd be able to debug it, then you would too.
<?php
include "includes/conn.php";
include "includes/functions.php";
if(isset($_GET['action']) and $_GET['action']=="myaccount" and isLoggedIn()){
include "includes/header.php";
include "templates/myaccounttemplate.php";
include "includes/footer.php";
}
else {
echo "not logged in";
}
?>