刚学习php,看了一本书上的例子,代码如下:
<html>
<head>
<title>Hi User</title>
</head>
<body>
<h1>Hi User</h1><?if (empty($userName)){
  print <<<HERE
  <form>
  Please enter your name:
  <input type = "text"
         name = "userName"><br>
  <input type = "submit">
  </form>
HERE;} else {
  print "<h3>Hi there, $userName!</h3>";
} //end
?></body>
</html>
但是我在输入上述代码后,保存为.php文件,用浏览器看结果的时候,发现else里的语句没有运行,请问这是什么问题?谢谢了

解决方案 »

  1.   

    什么书啊.什么时候出版的???有网络直接去 在线手册看例子就好了.http://cn.php.net/manual/zh/
      

  2.   

    if(!isset($userName))
    {
        print <<<HERE
      <form>
      Please enter your name:
      <input type = "text"
             name = "userName"><br>
      <input type = "submit">
      </form>
    HERE;
    }
    else
    {
        print "<h3>Hi there, $userName!</h3>";}这样试试看可以不可以????
      

  3.   

    建议看一下isset(),empty(),isnull()的区别
      

  4.   

    $userName 还没定义 empty($userName))为真,当然不执行else了
      

  5.   

    回复:icen123()
      用isset也不行
      

  6.   

    因为你的$username已经存在   empty($userName)==true 所以else 不执行