运行php文件提示Notice: Undefined index: user in D:\WWW\index4.php on line 42

Notice: Undefined index: user inD:\WWW\index4.php on line 31
Notice: Undefined variable: user in D:\WWW\index4.php on line 43
刚接触php,运行一直提示出错,不知道是不是COOKIE弄错了的原因,该如何设置COOKIE来记住用户名呢?求高手指点,谢谢!
代码如下:

//先判断cookie是否为空先,如果不为空才显示 你好

<td>
<?php  if(!empty($_COOKIE['user'])) :?>
你好:<?php echo $_COOKIE['user'] ;?>
<?php endif; ?>
</td>

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-03-05
在第一行写上error_reporting(0);
第2个回答  推荐于2017-09-27
$name = $_COOKIE['user];
$sql = "select * from uservote where user ='".$name."'"; //变量名name 和 user别弄混了

//设置cookie
setcookie("user",$user, time()+3600*24);本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网