echo '<li><span class="glyphicon glyphicon-user"></span>Welcome echo $_SESSION["username"];</li>';
In the above code it is not displaying username variable.. instead it is simply echoing Welcome $_SESSION["username"];
FYI.. I have used session.start() in both the files
But how to display Welcome 'username'
You have an error. you should close quotes.
echo '<li><span class="glyphicon glyphicon-user"></span>Welcome' .$_SESSION["username"].'</li>';
If still doesn't show the username:
Turn on error_reporting or use var_dump to cehck if variable is set
<?php
error_reporting(-1);
<?php
var_dump($_SESSION);
and just note about templating. If you use this in a view (most of code is html) then try to use php temlating
<li>
<a href="signup.html">
<span class="glyphicon glyphicon-user"></span>Welcome <?= $_SESSION["username"] ?>
</a>
</li>
The part Welcome echo $_SESSION["username"]; is simply a STRING and would be echoed verbatim without any Evaluation, Processing or Parsing. And, by the way: You don't use an echo Statement within an echo statement. That should be like SAYING GOOD MORNING IN ENGLISH & GERMAN AT THE SAME TIME THROUGH THE SAME ONE SINGLE MOUTH: LOL :-)
You should have used Double Quotes to surround the String you wished to echo out and then use single quotes for the HTML DOM Element Attributes like "class" or "HREF". That way you, you could very easily echo your String without much fuss. Here's how:
<?php
echo "<li>
<a href='signup.html'>
<span class='glyphicon glyphicon-user'></span>Welcome {$_SESSION['username']}
</a>
</li>";
Try this
echo '<li><span class="glyphicon glyphicon-user"></span>Welcome '. $_SESSION["username"] .'</li>';
Related
How do i disable and enable an anchor tag based on order_status condition? I want to make my receipt button only be able to click when the order_status been updated to ($irow['order_status'] == 5. It would be much appreciated if you all can provide me a code demo to show me how should I implement this using php. Thanks!
I tried the below codes but it wasn't working. It shows the error of Parse error: syntax error, unexpected 'order_id' (T_STRING). I do not know why does this happens. Can you guys give me a help to implement this?
<?php
if($order_status == 5){
print ' <a id="receiptbtn" target="_blank"
href="
receipt.php?order_id=<?php echo $row['order_id']; ?>"
class="btn addtocart" style="font-size: 12px;"><span class="iconify" data-icon="bx:bx-download" data-inline="false"></span> Receipt</a>';
}
else{
print 'Receipt';
}
?>
You're already in <?php execution mode, you can't use <?php echo to include a string. <?php is being treated as literal text in the string, and the ' in $row['order_id'] is ending the string that you're printing.
Use the string concatenation operator to combine a variable with the string literal.
To disable a link use href="#". href="" means to reload the page.
<?php
if($irow['order_status'] == 5){
print ' <a id="receiptbtn" target="_blank"
href="receipt.php?order_id=' . $row['order_id'] . '"
class="btn addtocart" style="font-size: 12px;"><span class="iconify" data-icon="bx:bx-download" data-inline="false"></span> Receipt</a>';
}
else{
print 'Receipt';
}
?>
I am not able to find the error why my title is not displaying. This is my code:
echo '<br /><b style="display:block";>'.$name .'</b>';
echo '<i style="color:red";>'.$class.'';
Can you please help me?
Remove the unnecessary last single quotes '', Also put your semicolon ; inside the double quotes "
<?php
$title = 'this is title value'; //example title
$des = 'this is description'; // example description
echo '<br /><b style="font-size:1.5em;">'.$title.'</b>';
echo '<i style="font-size:18px;">'.$des;
?>
DEMO: https://eval.in/1044486
It is not recommended to echo HTML tags inside PHP script. Your code should have been written as follows. I see that closing tag </i> is missing as well. I hope this might solve your problem.
<br />
<b style="display:block;">
<?php echo $name;?>
</b>
<i style="color:red;">
<?php echo $class;?>
</i>
I have problem looping out pictures from a database.
I have no problem getting the information(string) that I need from the database. The problems accure when I try to use the string as a img src-tag.
My code:
<?php
foreach ($console as $con):
echo '<li>', $con['brand'], ', ',$con['pic'], '</li>';
echo'<div class="item2">
<a href="xboxconsol.html">
<img src=',$con['pic'],'/>
</a>
</div>';
endforeach;
?>
Note, the li-elements put out the correct information but when I use it in the img-tag it adds a "/" at the end on the string.
Example of list output:
Playstation, ../playstation.jpg
The picutre however output the URL to the pic as:
../playstation.jpg/
Where do the last "/" come from and how do I get rid of it?
You need to quote the attribute value.
echo'<div class="item2">
<a href="xboxconsol.html">
<img src="',$con['pic'],'"/>
</a>
</div>';
Currently the browser is guessing what the attribute should contain.
Which comes out as:
<img src="value/">
but you want:
<img src="value"/>
You need to quote your concatenations, be very careful how you output HTML from PHP.
I'd rather concatenate the variables like this instead:
foreach ($console as $con)
{
echo "<li>{$con['brand']} {$con['pic']}</li>";
echo "<div class='item2'>
<a href='xboxconsol.html'>
<img src=\"{$con['pic']}\" />
</a>
</div>";
}
It's way cleaner and more readable.
I am having a problem with this code
<?php
echo '<div class="post_note2">
<b>'.$lang['RENEW_SUCCESS'].'</b></div><br /><span class="orange"><b>HOME|VIEW AD</b></span>';
}
}?>
for some reason when the VIEW AD link is clicked it doesn't build it properly and still contains the php code in the link rather than the link to the actual ad page. is it an issue with an echo in an echo ?
I'm sure this isn't quite difficult to solve but I have been trying for far to long on my own and cant get it.
Thanks, any help would be great.
You actually had it right in the first part of your string. You can't have and echo statement inside of another echo statement. Use concatenation throughout your string:
<a href="' . $adurl . '"
You have two extra brackets at the end and php text inside your echo.
<?php
echo '
<div class="post_note2">
<b>'.$lang['RENEW_SUCCESS'].'</b>
</div>
<br />
<span class="orange">
<b>
HOME | VIEW AD
</b>
</span>';
?>
All fixed given that $adurl is defined.
This
<?php echo $adurl; ?>
Should be
' . $adurl . '
i.e.
echo '<div class="post_note2"><b>'.$lang['RENEW_SUCCESS'].'</b></div><br /><span class="orange"><b>HOME|<a href="'.$adurl.'>VIEW AD</a></b></span>';
<?php $picNumberSlide = "<div id='slidenumber'></div>" ;?>
Num Print
<div id="slidenumber"></div> -> (Picture slide number)
Link
<a href="share?picNum=<?php echo $picNumberSlide;?>">
Not work.
<div id='slidenumber'></div> slide number of the screen writes.
I intended to write inside the URL's
How i can do? Thank you!
(i sorry for Eng)
<?php $picNumberSlide = "<div id='slidenumber'></div>" ;?>
The above defines the $picNumberSlide variable as a div.
<a href="share?picNum=<?php echo $picNumberSlide;">
Here you are placing a div inside the href of an anchor, that will never work.
You need to assign the $picNumberSlide variable only the number you wish to use.
Then using
<a href="share?picNum=<?php echo $picNumberSlide; ?>">
will work.
$picNumberSlide should only = a number
Change <a href="share?picNum=<?php echo $picNumberSlide;">
To <a href="share?picNum=<?php echo $picNumberSlide;?>">
(You were missing the closing tag for php)