1

Sorry, struggling to find this on here, probably because its really simple. Just want to add a string to this code. Such as "Welcome: +$SESSION".

New to PHP dont really know how to add the extra line within this code.

<label class="welcome"><?PHP if(isset($_SESSION['u_username'])){echo $_SESSION['u_username'];}?></label>

2
  • what do you mean by "add the extra line within this code?" what extra line? Commented Jan 23, 2019 at 11:09
  • What is the problem here ? Commented Jan 23, 2019 at 11:09

2 Answers 2

2

There are few ways to add to the strings. In " " quotes directly, if using arrays etc within it then you have to remove quotes from the array key,

<label class="welcome"><?PHP if(isset($_SESSION['u_username'])){echo " Welcome $_SESSION[u_username]";}?></label>

OR adding it with .

<label class="welcome"><?PHP if(isset($_SESSION['u_username'])){echo "Welcome " .$_SESSION['u_username'];}?></label>
Sign up to request clarification or add additional context in comments.

Comments

1

You need to concatenate the two strings:

1) Welcome

2) $_SESSION['u_username']

You can do it by using . operator.

Unlike Java or JavaScript, PHP uses . for concatenation instead of +

So, your final code should be:

<label class="welcome">
<?php
if(isset($_SESSION['u_username'])) {
 echo 'Welcome ' . $_SESSION['u_username'];
}
?>
</label>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.