Pergunta

I have built a system where a user logs in and saves an avatar via CKEditor/KCFinder via textarea. It works as I want it to work. Images are saved in a folder and the path to them on a database. The problem comes when I try to display the images in a table. I keep on getting double html tags and I can't really find a way to escape them so that I get just what I need to display the images.

Here is the script: linklabel is the name of the row where the avatar path is saved

<?php
    require_once "../scripts/conector.php";

    if (!$_GET['pid']) {
    $pageid = '1';
    } else {
        $pageid = preg_replace('/[^0-9]/', "", $_GET['pid']); // filter everything but numbers for security
    }

    $sqlCommand = "SELECT id, linklabel FROM pages WHERE showing='1' ORDER BY id ASC"; 
    $query = mysqli_query($myConnection, $sqlCommand) or die('Error: ' . mysqli_error($myConnection)); 

    $listadeavatars = '';
    while ($row = mysqli_fetch_array($query)) { 
        $pid = $row["id"];
        $avatar = "<img src='" . $row["linklabel"] . "' height='160' width='160'/>";

        $listadeavatars .= '<tr>
                                <td>' . $avatar . '</td>
                                <td>' . $pid . '</td>
                            </tr>';
    } 
    mysqli_free_result($query);
?>

And here is the HTML output when I inspect the HTML:

<img width="160" height="160" src="<img alt="" src="/nysida/admin/kcfinder/upload/images/avatar/avatar.jpg" style="height:160px; width:160px" />">

How can I get rid of the double HTML in order to display the images?

UPDATE:

If I use simply $avatar = $row["linklabel"];, then the result will be the one shown below: enter image description here

Foi útil?

Solução

Seems like $row["linklabel"] already contains the whole <img> tag, just change

$avatar = "<img src='" . $row["linklabel"] . "' height='160' width='160'/>";

into

$avatar = $row["linklabel"];

UPDATE

If you're seeing the actual tag in your webpage, you need to also decode the image tag using html_entity_decode(), like so:

$avatar = html_entity_decode($row["linklabel"]);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top