How to print image out in html, using php echo and $_SESSION variable?How can I prevent SQL injection in PHP?Convert HTML + CSS to PDF with PHP?How do I give text or an image a transparent background using CSS?How do I get PHP errors to display?How to create an HTML button that acts like a link?How do I auto-resize an image to fit a 'div' container?How can I set the default value for an HTML <select> element?How do you parse and process HTML/XML in PHP?How does PHP 'foreach' actually work?Cannot display HTML string

What is the origin of the “clerics can create water” trope?

What exactly is a web font, and what does converting to one involve?

Why are two-stroke engines nearly unheard of in aviation?

What was the deeper meaning of Hermione wanting the cloak?

Tips for remembering the order of parameters for ln?

Abilities interrupting effects on a cast card

Why are there two bearded faces wearing red hats on my stealth bomber icon?

Can a Druid Wild Shaped as a horse use Horseshoes of Speed?

Carroll's interpretation of 1-forms

Can one guy with a duplicator trigger a nuclear apocalypse?

If people's daily habits are reliable then why is the stock market so unpredictable?

Is it safe to unplug a blinking USB drive after 'safely' ejecting it?

Applications of mathematics in clinical setting

Output Distinct Factor Cuboids

Amiga 500 OCS/ECS vs Mega Drive VDP

Whence comes increasing usage of "do" for "have" in ordering food?

Should the pagination be reset when changing the order?

How can I check that parent has more than 1 child?

Who are the people reviewing far more papers than they're submitting for review?

What's the word for a student who doesn't register but goes to a class anyway?

With a 500GB SSD and a 250GB SSD is it possible to mirror a 250GB partition on the 500GB with the 250GB SSD using ZFS?

Floating Point XOR

Persuading players to be less attached to a pre-session 0 character concept

What do you call the battery slot's ends?



How to print image out in html, using php echo and $_SESSION variable?


How can I prevent SQL injection in PHP?Convert HTML + CSS to PDF with PHP?How do I give text or an image a transparent background using CSS?How do I get PHP errors to display?How to create an HTML button that acts like a link?How do I auto-resize an image to fit a 'div' container?How can I set the default value for an HTML <select> element?How do you parse and process HTML/XML in PHP?How does PHP 'foreach' actually work?Cannot display HTML string






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I'm trying to print out a users image using PHP and HTML.
The user's image is saved inside the $_SESSION['usericon']



The error is on line 3.



I've tried removing the PHP tags and switched print_r out etc.



<?php
if (isset($_SESSION['userId']))
echo '<img class="img-responsive" src="img/<?php print_r($_SESSION['userIcon']); ?>">
<a href="settings.php">Settings</a>
<form action="lib/logout.php" method="POST">
<button type="submit" name="logout-submit">Logout</button>
</form>';
else {
?>









share|improve this question





















  • 1





    You are in a PHP code section already, so using <?php inside of that again makes absolutely no sense. Please go read up on some basics of string concatenation. (We should not have to explain those here, this site is not a replacement for tutorials etc.)

    – 04FS
    Mar 28 at 13:45







  • 3





    You could just concat the variable, not sure if this is still the syntax (not done php since v4): echo '<img class="img-responsive" src="img/' . $_SESSION['userIcon']) . '">';

    – Pete
    Mar 28 at 13:47












  • @executable I have assigned $_SESSION['userIcon'] to a variable but, when i look at the page source now i just do this: <img class="img-responsive" src="img/$userIcon">

    – Mikkel Hebel
    Mar 28 at 13:54

















0















I'm trying to print out a users image using PHP and HTML.
The user's image is saved inside the $_SESSION['usericon']



The error is on line 3.



I've tried removing the PHP tags and switched print_r out etc.



<?php
if (isset($_SESSION['userId']))
echo '<img class="img-responsive" src="img/<?php print_r($_SESSION['userIcon']); ?>">
<a href="settings.php">Settings</a>
<form action="lib/logout.php" method="POST">
<button type="submit" name="logout-submit">Logout</button>
</form>';
else {
?>









share|improve this question





















  • 1





    You are in a PHP code section already, so using <?php inside of that again makes absolutely no sense. Please go read up on some basics of string concatenation. (We should not have to explain those here, this site is not a replacement for tutorials etc.)

    – 04FS
    Mar 28 at 13:45







  • 3





    You could just concat the variable, not sure if this is still the syntax (not done php since v4): echo '<img class="img-responsive" src="img/' . $_SESSION['userIcon']) . '">';

    – Pete
    Mar 28 at 13:47












  • @executable I have assigned $_SESSION['userIcon'] to a variable but, when i look at the page source now i just do this: <img class="img-responsive" src="img/$userIcon">

    – Mikkel Hebel
    Mar 28 at 13:54













0












0








0


0






I'm trying to print out a users image using PHP and HTML.
The user's image is saved inside the $_SESSION['usericon']



The error is on line 3.



I've tried removing the PHP tags and switched print_r out etc.



<?php
if (isset($_SESSION['userId']))
echo '<img class="img-responsive" src="img/<?php print_r($_SESSION['userIcon']); ?>">
<a href="settings.php">Settings</a>
<form action="lib/logout.php" method="POST">
<button type="submit" name="logout-submit">Logout</button>
</form>';
else {
?>









share|improve this question
















I'm trying to print out a users image using PHP and HTML.
The user's image is saved inside the $_SESSION['usericon']



The error is on line 3.



I've tried removing the PHP tags and switched print_r out etc.



<?php
if (isset($_SESSION['userId']))
echo '<img class="img-responsive" src="img/<?php print_r($_SESSION['userIcon']); ?>">
<a href="settings.php">Settings</a>
<form action="lib/logout.php" method="POST">
<button type="submit" name="logout-submit">Logout</button>
</form>';
else {
?>






php html






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 14:06









executable

2,0682 gold badges11 silver badges27 bronze badges




2,0682 gold badges11 silver badges27 bronze badges










asked Mar 28 at 13:43









Mikkel HebelMikkel Hebel

45 bronze badges




45 bronze badges










  • 1





    You are in a PHP code section already, so using <?php inside of that again makes absolutely no sense. Please go read up on some basics of string concatenation. (We should not have to explain those here, this site is not a replacement for tutorials etc.)

    – 04FS
    Mar 28 at 13:45







  • 3





    You could just concat the variable, not sure if this is still the syntax (not done php since v4): echo '<img class="img-responsive" src="img/' . $_SESSION['userIcon']) . '">';

    – Pete
    Mar 28 at 13:47












  • @executable I have assigned $_SESSION['userIcon'] to a variable but, when i look at the page source now i just do this: <img class="img-responsive" src="img/$userIcon">

    – Mikkel Hebel
    Mar 28 at 13:54












  • 1





    You are in a PHP code section already, so using <?php inside of that again makes absolutely no sense. Please go read up on some basics of string concatenation. (We should not have to explain those here, this site is not a replacement for tutorials etc.)

    – 04FS
    Mar 28 at 13:45







  • 3





    You could just concat the variable, not sure if this is still the syntax (not done php since v4): echo '<img class="img-responsive" src="img/' . $_SESSION['userIcon']) . '">';

    – Pete
    Mar 28 at 13:47












  • @executable I have assigned $_SESSION['userIcon'] to a variable but, when i look at the page source now i just do this: <img class="img-responsive" src="img/$userIcon">

    – Mikkel Hebel
    Mar 28 at 13:54







1




1





You are in a PHP code section already, so using <?php inside of that again makes absolutely no sense. Please go read up on some basics of string concatenation. (We should not have to explain those here, this site is not a replacement for tutorials etc.)

– 04FS
Mar 28 at 13:45






You are in a PHP code section already, so using <?php inside of that again makes absolutely no sense. Please go read up on some basics of string concatenation. (We should not have to explain those here, this site is not a replacement for tutorials etc.)

– 04FS
Mar 28 at 13:45





3




3





You could just concat the variable, not sure if this is still the syntax (not done php since v4): echo '<img class="img-responsive" src="img/' . $_SESSION['userIcon']) . '">';

– Pete
Mar 28 at 13:47






You could just concat the variable, not sure if this is still the syntax (not done php since v4): echo '<img class="img-responsive" src="img/' . $_SESSION['userIcon']) . '">';

– Pete
Mar 28 at 13:47














@executable I have assigned $_SESSION['userIcon'] to a variable but, when i look at the page source now i just do this: <img class="img-responsive" src="img/$userIcon">

– Mikkel Hebel
Mar 28 at 13:54





@executable I have assigned $_SESSION['userIcon'] to a variable but, when i look at the page source now i just do this: <img class="img-responsive" src="img/$userIcon">

– Mikkel Hebel
Mar 28 at 13:54












4 Answers
4






active

oldest

votes


















1
















Here is a simple solution to your problem. You need to remove the php tags and use concatenation.



<?php
if (isset($_SESSION['userId']))
echo '<img class="img-responsive" src="img/'.$_SESSION['userIcon'].'">
<a href="settings.php">Settings</a>
<form action="lib/logout.php" method="POST">
<button type="submit" name="logout-submit">Logout</button>
</form>';
else


?>





share|improve this answer

























  • @executeable Worked, thank you! :D

    – Mikkel Hebel
    Mar 28 at 14:03


















1
















change



 echo '<img class="img-responsive" src="img/<?php print_r($_SESSION['userIcon']); ?>">


to



 echo '<img class="img-responsive" src="img/'.$_SESSION['userIcon']).'">';





share|improve this answer
































    0
















    You can use something like this:



    <?php
    if (isset($_SESSION['userId']))
    $img = sprintf('<img class="img-responsive" src="img/%s" />', $_SESSION['userIcon']);
    echo $img . ' <a href="settings.php">Settings</a>
    <form action="lib/logout.php" method="POST">
    <button type="submit" name="logout-submit">Logout</button>
    </form>';
    else
    // @todo

    ?>


    rsrs






    share|improve this answer
































      0
















      You have started a PHP code, within a PHP code...
      This is the correct img src:



      src="img/' . print_r($_SESSION['userIcon']) . '"


      I would suggest you store all (temporary) images on your server, and not in a session file :) Have a nice day.






      share|improve this answer



























        Your Answer






        StackExchange.ifUsing("editor", function ()
        StackExchange.using("externalEditor", function ()
        StackExchange.using("snippets", function ()
        StackExchange.snippets.init();
        );
        );
        , "code-snippets");

        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "1"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );














        draft saved

        draft discarded
















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55399140%2fhow-to-print-image-out-in-html-using-php-echo-and-session-variable%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        1
















        Here is a simple solution to your problem. You need to remove the php tags and use concatenation.



        <?php
        if (isset($_SESSION['userId']))
        echo '<img class="img-responsive" src="img/'.$_SESSION['userIcon'].'">
        <a href="settings.php">Settings</a>
        <form action="lib/logout.php" method="POST">
        <button type="submit" name="logout-submit">Logout</button>
        </form>';
        else


        ?>





        share|improve this answer

























        • @executeable Worked, thank you! :D

          – Mikkel Hebel
          Mar 28 at 14:03















        1
















        Here is a simple solution to your problem. You need to remove the php tags and use concatenation.



        <?php
        if (isset($_SESSION['userId']))
        echo '<img class="img-responsive" src="img/'.$_SESSION['userIcon'].'">
        <a href="settings.php">Settings</a>
        <form action="lib/logout.php" method="POST">
        <button type="submit" name="logout-submit">Logout</button>
        </form>';
        else


        ?>





        share|improve this answer

























        • @executeable Worked, thank you! :D

          – Mikkel Hebel
          Mar 28 at 14:03













        1














        1










        1









        Here is a simple solution to your problem. You need to remove the php tags and use concatenation.



        <?php
        if (isset($_SESSION['userId']))
        echo '<img class="img-responsive" src="img/'.$_SESSION['userIcon'].'">
        <a href="settings.php">Settings</a>
        <form action="lib/logout.php" method="POST">
        <button type="submit" name="logout-submit">Logout</button>
        </form>';
        else


        ?>





        share|improve this answer













        Here is a simple solution to your problem. You need to remove the php tags and use concatenation.



        <?php
        if (isset($_SESSION['userId']))
        echo '<img class="img-responsive" src="img/'.$_SESSION['userIcon'].'">
        <a href="settings.php">Settings</a>
        <form action="lib/logout.php" method="POST">
        <button type="submit" name="logout-submit">Logout</button>
        </form>';
        else


        ?>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 28 at 13:58









        executableexecutable

        2,0682 gold badges11 silver badges27 bronze badges




        2,0682 gold badges11 silver badges27 bronze badges















        • @executeable Worked, thank you! :D

          – Mikkel Hebel
          Mar 28 at 14:03

















        • @executeable Worked, thank you! :D

          – Mikkel Hebel
          Mar 28 at 14:03
















        @executeable Worked, thank you! :D

        – Mikkel Hebel
        Mar 28 at 14:03





        @executeable Worked, thank you! :D

        – Mikkel Hebel
        Mar 28 at 14:03













        1
















        change



         echo '<img class="img-responsive" src="img/<?php print_r($_SESSION['userIcon']); ?>">


        to



         echo '<img class="img-responsive" src="img/'.$_SESSION['userIcon']).'">';





        share|improve this answer





























          1
















          change



           echo '<img class="img-responsive" src="img/<?php print_r($_SESSION['userIcon']); ?>">


          to



           echo '<img class="img-responsive" src="img/'.$_SESSION['userIcon']).'">';





          share|improve this answer



























            1














            1










            1









            change



             echo '<img class="img-responsive" src="img/<?php print_r($_SESSION['userIcon']); ?>">


            to



             echo '<img class="img-responsive" src="img/'.$_SESSION['userIcon']).'">';





            share|improve this answer













            change



             echo '<img class="img-responsive" src="img/<?php print_r($_SESSION['userIcon']); ?>">


            to



             echo '<img class="img-responsive" src="img/'.$_SESSION['userIcon']).'">';






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 28 at 14:04









            Danyal SandeeloDanyal Sandeelo

            9,0363 gold badges26 silver badges46 bronze badges




            9,0363 gold badges26 silver badges46 bronze badges
























                0
















                You can use something like this:



                <?php
                if (isset($_SESSION['userId']))
                $img = sprintf('<img class="img-responsive" src="img/%s" />', $_SESSION['userIcon']);
                echo $img . ' <a href="settings.php">Settings</a>
                <form action="lib/logout.php" method="POST">
                <button type="submit" name="logout-submit">Logout</button>
                </form>';
                else
                // @todo

                ?>


                rsrs






                share|improve this answer





























                  0
















                  You can use something like this:



                  <?php
                  if (isset($_SESSION['userId']))
                  $img = sprintf('<img class="img-responsive" src="img/%s" />', $_SESSION['userIcon']);
                  echo $img . ' <a href="settings.php">Settings</a>
                  <form action="lib/logout.php" method="POST">
                  <button type="submit" name="logout-submit">Logout</button>
                  </form>';
                  else
                  // @todo

                  ?>


                  rsrs






                  share|improve this answer



























                    0














                    0










                    0









                    You can use something like this:



                    <?php
                    if (isset($_SESSION['userId']))
                    $img = sprintf('<img class="img-responsive" src="img/%s" />', $_SESSION['userIcon']);
                    echo $img . ' <a href="settings.php">Settings</a>
                    <form action="lib/logout.php" method="POST">
                    <button type="submit" name="logout-submit">Logout</button>
                    </form>';
                    else
                    // @todo

                    ?>


                    rsrs






                    share|improve this answer













                    You can use something like this:



                    <?php
                    if (isset($_SESSION['userId']))
                    $img = sprintf('<img class="img-responsive" src="img/%s" />', $_SESSION['userIcon']);
                    echo $img . ' <a href="settings.php">Settings</a>
                    <form action="lib/logout.php" method="POST">
                    <button type="submit" name="logout-submit">Logout</button>
                    </form>';
                    else
                    // @todo

                    ?>


                    rsrs







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 28 at 14:01









                    Lucas CampeloLucas Campelo

                    12 bronze badges




                    12 bronze badges
























                        0
















                        You have started a PHP code, within a PHP code...
                        This is the correct img src:



                        src="img/' . print_r($_SESSION['userIcon']) . '"


                        I would suggest you store all (temporary) images on your server, and not in a session file :) Have a nice day.






                        share|improve this answer





























                          0
















                          You have started a PHP code, within a PHP code...
                          This is the correct img src:



                          src="img/' . print_r($_SESSION['userIcon']) . '"


                          I would suggest you store all (temporary) images on your server, and not in a session file :) Have a nice day.






                          share|improve this answer



























                            0














                            0










                            0









                            You have started a PHP code, within a PHP code...
                            This is the correct img src:



                            src="img/' . print_r($_SESSION['userIcon']) . '"


                            I would suggest you store all (temporary) images on your server, and not in a session file :) Have a nice day.






                            share|improve this answer













                            You have started a PHP code, within a PHP code...
                            This is the correct img src:



                            src="img/' . print_r($_SESSION['userIcon']) . '"


                            I would suggest you store all (temporary) images on your server, and not in a session file :) Have a nice day.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 28 at 14:01









                            Hans SchiesslHans Schiessl

                            92 bronze badges




                            92 bronze badges































                                draft saved

                                draft discarded















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55399140%2fhow-to-print-image-out-in-html-using-php-echo-and-session-variable%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                                SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                                은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현