How to display images from phpmysql server with base64_encode? [PHP + HTML]












1















This image shows the products table that I am using to upload my image from the back-end side and I wanted to display it on the front-end page.
I realize that the picture that I have uploaded through the back end side only saved as '48 B' but when I was uploading it through MySQL manually it saved as '64 KiB', although both are the same file.



When it comes to displaying the 48 B Image file would not show.



[code1] This is the code that I am using to insert the image from the back-end.



if(isset($_POST['submit'])){
$pid = mysql_real_escape_string($_POST['productID']);
$productName = mysql_real_escape_string($_POST['productName']);
$productImg = mysql_real_escape_string($_POST['productImg']);

$insert = mysql_query("INSERT INTO products (productID, productName, productImg) VALUES ('$pid', '$productName', '$productImg')");

if($insert)
{
echo 'Successfully added new record.';
} else {
echo 'Failed to add new record because '.mysql_error();
}


}
?>



[code2] and this is the code that I am using to display the image from the front-end.



while($row = mysql_fetch_array($query)){
echo '<tr>

<td>'.$row['productID'].'</td>
<td>'.$row['productName'].'</td>
<td>'.
'<img src="data:image/jpg;base64,'.base64_encode($row['productImg']).'" width="auto" height="150" class="img-thumnail"/>'
.'</td>


I think the problem is in the insertion code [code1] even though all the data successfully inserted.










share|improve this question

























  • It should be data:image/jpg not data:productImg/jpg.

    – FrankerZ
    Oct 22 '18 at 9:00











  • Refer this link stackoverflow.com/questions/17717506/… to insert image in database

    – Talk2Nit
    Oct 22 '18 at 9:05











  • @FrankerZ thank you for the correction, but still, it has no changes.

    – Json
    Oct 23 '18 at 2:50
















1















This image shows the products table that I am using to upload my image from the back-end side and I wanted to display it on the front-end page.
I realize that the picture that I have uploaded through the back end side only saved as '48 B' but when I was uploading it through MySQL manually it saved as '64 KiB', although both are the same file.



When it comes to displaying the 48 B Image file would not show.



[code1] This is the code that I am using to insert the image from the back-end.



if(isset($_POST['submit'])){
$pid = mysql_real_escape_string($_POST['productID']);
$productName = mysql_real_escape_string($_POST['productName']);
$productImg = mysql_real_escape_string($_POST['productImg']);

$insert = mysql_query("INSERT INTO products (productID, productName, productImg) VALUES ('$pid', '$productName', '$productImg')");

if($insert)
{
echo 'Successfully added new record.';
} else {
echo 'Failed to add new record because '.mysql_error();
}


}
?>



[code2] and this is the code that I am using to display the image from the front-end.



while($row = mysql_fetch_array($query)){
echo '<tr>

<td>'.$row['productID'].'</td>
<td>'.$row['productName'].'</td>
<td>'.
'<img src="data:image/jpg;base64,'.base64_encode($row['productImg']).'" width="auto" height="150" class="img-thumnail"/>'
.'</td>


I think the problem is in the insertion code [code1] even though all the data successfully inserted.










share|improve this question

























  • It should be data:image/jpg not data:productImg/jpg.

    – FrankerZ
    Oct 22 '18 at 9:00











  • Refer this link stackoverflow.com/questions/17717506/… to insert image in database

    – Talk2Nit
    Oct 22 '18 at 9:05











  • @FrankerZ thank you for the correction, but still, it has no changes.

    – Json
    Oct 23 '18 at 2:50














1












1








1








This image shows the products table that I am using to upload my image from the back-end side and I wanted to display it on the front-end page.
I realize that the picture that I have uploaded through the back end side only saved as '48 B' but when I was uploading it through MySQL manually it saved as '64 KiB', although both are the same file.



When it comes to displaying the 48 B Image file would not show.



[code1] This is the code that I am using to insert the image from the back-end.



if(isset($_POST['submit'])){
$pid = mysql_real_escape_string($_POST['productID']);
$productName = mysql_real_escape_string($_POST['productName']);
$productImg = mysql_real_escape_string($_POST['productImg']);

$insert = mysql_query("INSERT INTO products (productID, productName, productImg) VALUES ('$pid', '$productName', '$productImg')");

if($insert)
{
echo 'Successfully added new record.';
} else {
echo 'Failed to add new record because '.mysql_error();
}


}
?>



[code2] and this is the code that I am using to display the image from the front-end.



while($row = mysql_fetch_array($query)){
echo '<tr>

<td>'.$row['productID'].'</td>
<td>'.$row['productName'].'</td>
<td>'.
'<img src="data:image/jpg;base64,'.base64_encode($row['productImg']).'" width="auto" height="150" class="img-thumnail"/>'
.'</td>


I think the problem is in the insertion code [code1] even though all the data successfully inserted.










share|improve this question
















This image shows the products table that I am using to upload my image from the back-end side and I wanted to display it on the front-end page.
I realize that the picture that I have uploaded through the back end side only saved as '48 B' but when I was uploading it through MySQL manually it saved as '64 KiB', although both are the same file.



When it comes to displaying the 48 B Image file would not show.



[code1] This is the code that I am using to insert the image from the back-end.



if(isset($_POST['submit'])){
$pid = mysql_real_escape_string($_POST['productID']);
$productName = mysql_real_escape_string($_POST['productName']);
$productImg = mysql_real_escape_string($_POST['productImg']);

$insert = mysql_query("INSERT INTO products (productID, productName, productImg) VALUES ('$pid', '$productName', '$productImg')");

if($insert)
{
echo 'Successfully added new record.';
} else {
echo 'Failed to add new record because '.mysql_error();
}


}
?>



[code2] and this is the code that I am using to display the image from the front-end.



while($row = mysql_fetch_array($query)){
echo '<tr>

<td>'.$row['productID'].'</td>
<td>'.$row['productName'].'</td>
<td>'.
'<img src="data:image/jpg;base64,'.base64_encode($row['productImg']).'" width="auto" height="150" class="img-thumnail"/>'
.'</td>


I think the problem is in the insertion code [code1] even though all the data successfully inserted.







php html image insert display






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 3:15







Json

















asked Oct 22 '18 at 8:58









JsonJson

135




135













  • It should be data:image/jpg not data:productImg/jpg.

    – FrankerZ
    Oct 22 '18 at 9:00











  • Refer this link stackoverflow.com/questions/17717506/… to insert image in database

    – Talk2Nit
    Oct 22 '18 at 9:05











  • @FrankerZ thank you for the correction, but still, it has no changes.

    – Json
    Oct 23 '18 at 2:50



















  • It should be data:image/jpg not data:productImg/jpg.

    – FrankerZ
    Oct 22 '18 at 9:00











  • Refer this link stackoverflow.com/questions/17717506/… to insert image in database

    – Talk2Nit
    Oct 22 '18 at 9:05











  • @FrankerZ thank you for the correction, but still, it has no changes.

    – Json
    Oct 23 '18 at 2:50

















It should be data:image/jpg not data:productImg/jpg.

– FrankerZ
Oct 22 '18 at 9:00





It should be data:image/jpg not data:productImg/jpg.

– FrankerZ
Oct 22 '18 at 9:00













Refer this link stackoverflow.com/questions/17717506/… to insert image in database

– Talk2Nit
Oct 22 '18 at 9:05





Refer this link stackoverflow.com/questions/17717506/… to insert image in database

– Talk2Nit
Oct 22 '18 at 9:05













@FrankerZ thank you for the correction, but still, it has no changes.

– Json
Oct 23 '18 at 2:50





@FrankerZ thank you for the correction, but still, it has no changes.

– Json
Oct 23 '18 at 2:50












1 Answer
1






active

oldest

votes


















1














if you are using <input type="file" /> and if you are not aware this that "you cannot send file type like normal string" check that what you are doing before submit.



Refer this link it may help you:
https://www.codexworld.com/store-retrieve-image-from-database-mysql-php/






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/3.0/"u003ecc by-sa 3.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%2f52925642%2fhow-to-display-images-from-phpmysql-server-with-base64-encode-php-html%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    if you are using <input type="file" /> and if you are not aware this that "you cannot send file type like normal string" check that what you are doing before submit.



    Refer this link it may help you:
    https://www.codexworld.com/store-retrieve-image-from-database-mysql-php/






    share|improve this answer




























      1














      if you are using <input type="file" /> and if you are not aware this that "you cannot send file type like normal string" check that what you are doing before submit.



      Refer this link it may help you:
      https://www.codexworld.com/store-retrieve-image-from-database-mysql-php/






      share|improve this answer


























        1












        1








        1







        if you are using <input type="file" /> and if you are not aware this that "you cannot send file type like normal string" check that what you are doing before submit.



        Refer this link it may help you:
        https://www.codexworld.com/store-retrieve-image-from-database-mysql-php/






        share|improve this answer













        if you are using <input type="file" /> and if you are not aware this that "you cannot send file type like normal string" check that what you are doing before submit.



        Refer this link it may help you:
        https://www.codexworld.com/store-retrieve-image-from-database-mysql-php/







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Oct 22 '18 at 9:53









        sakethsaketh

        1169




        1169






























            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%2f52925642%2fhow-to-display-images-from-phpmysql-server-with-base64-encode-php-html%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

            Florida Star v. B. J. F.

            Error while running script in elastic search , gateway timeout

            Adding quotations to stringified JSON object values