Hi all i have this code which is getting setting the username and password if it matches and doesnt seem to be working correctly with my login this i what i have atm.
error_reporting(E_ALL);
require("dbconnect.php");
$msg_pass="";
$msg_user="";
$username = mysqli_real_escape_string($con,stripslashes(trim($_POST['username'])));
$password = mysqli_real_escape_string($con,stripslashes(trim($_POST['password'])));
$cQuery="SELECT * FROM members WHERE username='".$username."' AND Password='".$password."'";
$con;
//echo $cQuery;
$rs=mysqli_query($con,$cQuery);
if(!$rs)
{
echo "Unable to excute the query:".mysqli_error($con);
}
else
{
$count=mysqli_num_rows($rs);
if($count>0)
{
$data=mysqli_fetch_assoc($rs);
if($data['password']=$password)
{
if($remember)
{
echo "Remember is being set";
//
$time = time();
setcookie("BCCMS",$username,$time +3600);
setcookie("BCCMS",$password,$time +3600);
$today=date("Ymd");
if(isset($_COOKIE['BCCMS']))
{
echo "Cookie has been set cookie monster is happy";
$_SESSION['user']=$username;
//
$dQuery="UPDATE members SET LastedLogin='$today',signons=signons+1,onlinestatus='1' WHERE username='".$COOKIE["BCCMS"]."'";
echo $dQuery;
$rs=mysqli_query($con,$dQuery);
if(!$rs)
{
echo "Error:".mysqli_error($con);
}
else
{
echo "";
}
//
}
else
{
echo "Cookie monster is unhappy";
}
echo "Logged in as: ".$_SESSION['user']."<br/>";
echo "Please Wait while we log you in";
//echo "<META HTTP-EQUIV=\\"Refresh\\" CONTENT=\\"1; URL=members.php\\">";
//
}
else
{
echo "remember me feature not being used";
$_SESSION['user']=$username;
//
$today=date("Ymd");
$dQuery="UPDATE members SET LastedLogin='$today',signons=signons+1,onlinestatus='1' WHERE username='".$_SESSION['user']."'";
$rs=mysqli_query($con,$dQuery);
if(!$rs)
{
echo "Error:".mysqli_error($con);
}
else
{
echo "";
}
echo "Logged in as: ".$_SESSION['user']."<br/>";
echo "Please Wait while we log you in";
//echo "<META HTTP-EQUIV=\\"Refresh\\" CONTENT=\\"1; URL=members.php\\">";
//
}
}
else
{
$msg_pass="Wrong Password,Please Try again<br>\
";
$rmt = $_SERVER["REMOTE_ADDR"];
$today=date("F j,Y,g:i a");
if($rmt || $today)
{
$pQuery="insert into failedlogins values('','$username','$password','$rmt','$today')";
$result=mysqli_query($con,$pQuery);
if(!$result)
{
echo "Error:".mysqli_connect_errno();
echo "<br/>Error2:".mysqli_error($con);
}
else
{
echo "Your Ip Address has been Logged!";
}
}
}
}
else
{
$msg_user="Wrong Username,Please Try again<br>\
";
$rmt = $_SERVER["REMOTE_ADDR"];
$today=date("F j,Y,g:i a");
if($rmt || $today)
{
$pQuery="insert into failedlogins values('','$username','$password','$rmt','$today')";
$result=mysqli_query($con,$pQuery);
if(!$result)
{
echo "Error:".mysqli_connect_errno();
echo "<br/>Error2:".mysqli_error($con);
}
else
{
echo "Your Ip Address has been Logged!";
}
}
}
}
When i do the check if remember me is checked it goes into it but when i do i
if(isset($_COOKIE['BCCMS']))
{
echo "Cookie has been set cookie monster is happy";
$_SESSION['user']=$username;
//
$dQuery="UPDATE members SET LastedLogin='$today',signons=signons+1,onlinestatus='1' WHERE username='".$COOKIE["BCCMS"]."'";
echo $dQuery;
$rs=mysqli_query($con,$dQuery);
if(!$rs)
{
echo "Error:".mysqli_error($con);
}
else
{
echo "";
}
//
}
else
{
echo "Cookie monster is unhappy";
}
Just prints out saying cookie monster is unhappy for cookie not being set when it should be not sure what i am doing is wrong?
Can anyone help me?
Thanks,William