-2

Hi I'm kind of new to the site and to php. I am trying to make a code which tells hello to a user if logged in or displays the Register/Login form if the user is logged out. Following is the code for it :

<?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 !
        }. ?>

But it gives me an error :

                                   PHP Error Message

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

And the 63rd line is this one :

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

Please if anyone can help me, Please help ! Thanks in advance ! This not the duplicate i just want someone to tell me where i am wrong and correct that mistake .

DentFuse
  • 21
  • 2
  • 7

2 Answers2

0

You're messing up with the concatenation.

Change this:

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

to this:

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

and this:

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

to this:

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

EDIT:

Since I could not find a online PHP/HTML compiler, to show that the above code works I have attached a picture:

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.

DirtyBit
  • 16,613
  • 4
  • 34
  • 55
0

You missed a echo before your output string:

echo "Hello " . htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8'); 
echo "you currently have " . $_SESSION['user']['point'];
echo "points !";
dbarthel
  • 130
  • 1
  • 11
  • It Accepted line 63 now and executed the code but it did not display my points or said hello to me when i logged in. – DentFuse Sep 27 '15 at 11:40