I am trying to pass my database id to call an image in another directory

Asked

Viewed 26 times

0

I’m having some problems to insert an image on the site, I already uploaded but I’m not able to call it from the directory with php.

I’m getting two errors:

1-Notice: Undefined index: file in C: xampp htdocs Control panel products.php on line 7

2-Recoverable fatal error: Object of class mysqli_result could not be converted to string in C: xampp htdocs Control panel products.php on line 96

The cidigo used:

<?php
session_start();
include 'conn_prod.php';
require 'processa_img.php';

$id = mysqli_query($conn_prod,"SELECT id FROM necessaires;");

?>

Here comes part of html

<div class="log_prods"> 
<div class="corpo_log">
<?php

//RECEBER O NUMERO DA PAGINA
    $pagina_atual   =   filter_input(INPUT_GET, 'pagina');

     $pagina = (!empty($pagina_atual))  ?  $pagina_atual : 1;

//SETAR A QUANTIDADE DE ITENS POR PAGINA
     $quant_result_pg = 5;

//CALCULAR O INICIO DA VISUALIZAÇÃO
     $inicio = ($quant_result_pg * $pagina) - $quant_result_pg;



    $pegar_result = "SELECT * FROM necessaires LIMIT $inicio, $quant_result_pg";
    $result_produtos = mysqli_query($conn_prod, $pegar_result);

        while ($row_produto = mysqli_fetch_assoc($result_produtos)) {
            # code...
            echo "<section><span>Tema :</span>" . $row_produto['tema'] . "<br>
                  <span>ID :</span>" . $row_produto['id_nec'] . "<div class='cont_img-prod'><img src=" ?><?php echo "upload/$id/";               "</div></section><hr>";
        };
        ?>
        <?php

//  PAGINAÇÃO - SOMAR A QUANTIDADE DE USUARIOS
    $result_pg = "SELECT COUNT(id) AS num_result FROM necessaires";
    $resultado_pg = mysqli_query($conn_prod, $result_pg);
    $row_pg = mysqli_fetch_assoc($resultado_pg);
    //echo $row_pg['num_result'];

//QUANTIDADE DE PAGINAS

    $quantidade_pg = ceil($row_pg['num_result'] / $quant_result_pg);
    ?>
</div>
    <div class="cont_setas"><div class="setas_">
    <?php

//LIMITAR OS LINKS ANTES E DEPOIS
    $max_links = 1;
    echo "<a href='produtos.php?pagina=1'><i class='pag_pri fas fa-angle-double-left'></i></a>";

        for ($pag_ant = $pagina - $max_links; $pag_ant <= $pagina - 1; $pag_ant ++) { 
            # code...
            if ($pag_ant >= 1){

                echo "<a href='produtos.php?pagina=$pag_ant'>$pag_ant</a>";
            }
        }

    echo "$pagina";

    for($pag_dep = $pagina + 1; $pag_dep <= $pagina + $max_links; $pag_dep ++){

                if ($pag_dep <= $quantidade_pg) {
                    # code...
                    echo "<a href='produtos.php?pagina=$pag_dep'>$pag_dep</a>";
                }
    }

    echo "<a href='produtos.php?pagina=$quantidade_pg'><i class='pag_ult fas fa-angle-double-right'></i></a>";
?>
    </div></div>

Thanks for your help.

1 answer

0


Hello, in the part of img src you need to concaternar, you are putting the variable $id as if it were a text. would be something like this:

From a look at concatenation in PHP -

  • thank you very much, the first mistake was solved but the second was not and it is exactly this second that I have no idea what it is

  • could show exactly which line is giving the error? Could put line 96 of the page products.php

  • echo "<Section><span>Theme :</span>" . $row_product['theme'] . " <br> <span>ID :</span>" . $row_product['id_nec'] . " <div class='cont_img-Prod'><img src=" . 'upload/$id' ">; ></div></Section><hr>";

  • the error that has returned me: Recoverable fatal error: Object of class mysqli_result could not be converted to string in C: xampp htdocs Control panel products.php on line 7 - it’s the first time I’ve come across it, gone.

  • Oh yes, I found the error! In the part di img src you need to concaternar, you are putting the variable $id as if it were a text. would look something like this: <img src="upload. '$id'." > . Take a look at PHP concatenation

  • I got it!! Thank you very much!!

  • For nothing, I will change the answer! Could you choose the correct answer? Thank you

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.