php创建cookie不在if else语句中工作

时间:2017-01-24 16:29:07

标签: php mysql cookies

我有一个PHP代码

$cookie_name = "John";
$cookie_age = "28";

   setcookie("nameee", $cookie_name, time()+3600, "/","", 0);
   setcookie("ageee", $cookie_age, time()+3600, "/", "",  0);

当在独立文件中使用此代码时,它可以正常工作。但是当它在if else语句中使用时,如下所示它不起作用

$sql="SELECT * FROM regusers WHERE email='$email' AND password='$upass' AND active=1"; 
$result=mysql_query($sql);
$count=mysql_num_rows($result); 

//If count is 0 , then enter the values
if($count=="0"){ 
$error = "Email or Password does not Match !";
}

else if($count!="0")
 {

$cookie_name = "John";
$cookie_age = "28";

   setcookie("nameee", $cookie_name, time()+3600, "/","", 0);
   setcookie("ageee", $cookie_age, time()+3600, "/", "",  0);


$error = "Login Successful. Redirecting to admin page  !";
echo '<script language="javascript">';
echo 'document.location.href="cpanel.php"';
echo '</script>';



 } 


 // else update the values 
 else {

}

请帮助我。提前谢谢..

0 个答案:

没有答案