Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
How to display MediumBLOB from MySQL database using Javascript

So I am trying to display the information that I have retrieved from a database and I'm using Javascript to pass these info to their corresponding tags using the IDs. I have no problem with outputting the text, but I am having a hard time to output the images in the database which is a MediumBLOB.

function ShowDetails(viewid)
        {
            $('#view').val(viewid)
            $.post("update.php",{sendview:viewid},function(data,
            status){
                var userid = JSON.parse(data);
                $('#uname').text("Username: " + userid.username)
                $('#pass').text("Password: " + userid.password)
                $('#fname').text("First Name: " + userid.firstname)
                $('#mname').text("Middle Name: " + userid.middlename)
                $('#lname').text("Last Name: " + userid.lastname)
                $('#gen').text("Gender: " + userid.gender)
                $('#yearlevel').text("Year Level: " + userid.yearlevel)
                $('#pos').text("Position: " + userid.position)
                $('#accesslevel').text("Access Level: " + userid.accesslevel)       
                var buffer = new Buffer(userid.images);
                var bufferBase64 = buffer.toString('base64');
                $('#img').attr("src", "data:image/jpeg;base64," + bufferBase)               
            });

            $('#viewModal').modal("show");
        }

As for the update.php, here is the condition that receives the Post method.

<?php
$conn = mysqli_connect('localhost', 'root', '', 'phpfinals');
if($conn->connect_error)
{
    echo "$conn->connect_error";
    die("Connection Failed : ".$conn->connect_error);
}

 //Sending details to be viewed
if(isset($_POST['sendview']))
{
    $user_id = $_POST['sendview'];
    $stmnt = mysqli_query($conn,"SELECT `username`, `password`, `firstname`, `middlename`, `lastname` , `gender`, `yearlevel`, `position`, `accesslevel`, `images` FROM phpfinals.records WHERE `username` = $user_id");
    $result=array();
    while($row = mysqli_fetch_assoc($stmnt))
    {
        $result = $row;
    }
    echo json_encode($result);
}

else
{
    $response['status'] = 200;
    $response['message'] = "Invalid or data not found";
}
?>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

try creating an URL object

 function ShowDetails(viewid)
    {
        $('#view').val(viewid)
        $.post("update.php",{sendview:viewid},function(data,
        status){
            var userid = JSON.parse(data);
            $('#uname').text("Username: " + userid.username)
            $('#pass').text("Password: " + userid.password)
            $('#fname').text("First Name: " + userid.firstname)
            $('#mname').text("Middle Name: " + userid.middlename)
            $('#lname').text("Last Name: " + userid.lastname)
            $('#gen').text("Gender: " + userid.gender)
            $('#yearlevel').text("Year Level: " + userid.yearlevel)
            $('#pos').text("Position: " + userid.position)
            $('#accesslevel').text("Access Level: " + userid.accesslevel)       

           var objectURL = URL.createObjectURL(userid.images);   
           $('#img').attr("src", objectURL)             
        });

        $('#viewModal').modal("show");
    }

and as a suggestion not related to your question instead of echo should be better use return for send the result

return json_encode($result);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!