Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda