如何用这段代码连接sql、html和php

sczxawaw  于 2021-06-19  发布在  Mysql
关注(0)|答案(1)|浏览(547)

基本上,它是一个元素,用于显示来自数据库路径的图像。但我就是做不到。

<img class="img-circle profile_img" id="blah" src=" <?php $query2=mysqli_query($conexao,"select * FROM esc_usuarios_fotos WHERE img_usu_codigo = '" . $_SESSION['codigo'] . "'");
    while($row2=mysqli_fetch_array($query2)){
        if ((!empty($row2['img_local'])) && (file_exists($row2['img_local']))) {
            echo '<img class="image--cover" id="blah" src="'.$row2['img_local'].'" alt="Avatar" title="DEFINIDA" onerror="this.onerror=null;this.src=1.png;">';
        } else {
            echo 'Show a default image.'; // <img src="path_to_default_image" alt="Default_image"/>
        }
    } ?>" alt="Avatar" title="DEFINIDA" >
1qczuiv0

1qczuiv01#

我成功地工作了,最后的代码:

<?php
            $query2=mysqli_query($conexao,"select * FROM esc_usuarios_fotos WHERE img_usu_codigo = '" . $_SESSION['codigo'] . "'");
            while($row2=mysqli_fetch_array($query2)){
                if ((!empty($row2['img_local'])) && (file_exists($row2['img_local']))) {
                    echo '<img class="image--profile" src="'.$row2['img_local'].'" title="Clique para abrir seu perfil">';
                } else {
                    echo '<img class="image--profile" src="images/user.png">';
                }
              }
            ?>

相关问题