2015-09-27 87 views
-2

嗨,我是一种新的网站和PHP。我正在尝试创建一个代码,告诉用户如果登录,或者如果用户注销,则显示注册/登录表单。下面是它的代码:如何在php中添加链接

<?php  if(empty($_SESSION['user'])) 
     {echo " <a href=register.php >Register </a> Or <a href=login.php>Login</a>" ;   
     } 
     else{ 
     Hello htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8'); you currently have $_SESSION['user']['point']; points ! 
     }. ?> 

但它给我一个错误:

        PHP Error Message 

Parse error: syntax error, unexpected T_STRING in /home/a3897717/public_html/index1.php on line 63 

和第63行是这一个:

Hello htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8'); you currently have $_SESSION['user']['point']; points ! 

请如果有人能帮助我,请帮忙 ! 在此先感谢!这不是重复,我只是想让别人告诉我我错在哪里,并纠正错误。

回答

0

你搞砸了串联

更改此:

echo "<a href=register.php >Register </a> Or <a href=login.php>Login</a>"; 

这样:

echo "<a href='register.php'>Register </a> Or <a href='login.php'>Login</a>"; 

这:

Hello htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8'); you currently have $_SESSION['user']['point']; points ! 

这样:

echo "Hello " . htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8') . "you currently have " . $_SESSION['user']['point'] . "points!"; 

编辑:

因为我无法找到一个在线的PHP/HTML编译器,以表明上面的代码工作我附上一张照片:

enter image description here

Note: It is obvious that the error is shown as the sessions are not defined and neither was the core problem of this question.

+0

不,它帮助。现在它开始在第60行给我错误!第63行之前我的问题是......第60行非常好。 – DentFuse

+0

@TheGamingGuy在线60是什么?和你得到什么错误? – user5173426

+0

Line 60:echo“Register or Login”; 和我得到的错误:解析错误:语法错误,意想不到的T_ECHO在/home/a3897717/public_html/index1.php在线60 – DentFuse

0

你错过了回音在输出字符串之前:

echo "Hello " . htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8'); 
echo "you currently have " . $_SESSION['user']['point']; 
echo "points !"; 
+0

它接受63行现在和执行的代码,但它没有显示我的观点或当我登录时向我打招呼。 – DentFuse