Image does not appear - php

Asked

Viewed 251 times

0

I’m trying to bring the Mysql database image to a PHP page but it doesn’t appear.

Follows the code:

<!doctype html>
<html>
<head>

<script src="jquery.js" type="text/javascript"></script>
<script src="jquery.validate.js" type="text/javascript"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://jqueryvalidation.org/files/dist/jquery.validate.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script src="http://jqueryvalidation.org/files/dist/jquery.validate.js"></script>
<script src="http://jqueryvalidation.org/files/dist/additional-methods.min.js"></script>

<link href="css/bootstrap.css" rel="stylesheet">

<title></title>
</head>

<body>

<?php

$conexao = mysqli_connect("localhost","root","") 
or die("Erro na conexão com banco de dados");      
$select_db = mysqli_select_db($conexao,"mentoria"); 
$campos = array(".", "-");      


$cpf = str_replace($campos,"",$_POST["inputCPF"]);

$consulta_jovens = "SELECT jfoto,jnome,jfaixaetaria,jescolaridade,jhobby,jcomida,jmusica,jesporte,jtime,jcaracteristica,janimal,jlivro,jsonho, ((CASE WHEN jovem.jfaixaetaria = mentor.mfaixaetaria THEN 1 ELSE 0 END)+(CASE WHEN jovem.jescolaridade = mentor.mescolaridade THEN 1 ELSE 0 END)+(CASE WHEN jovem.jhobby = mentor.mhobby THEN 1 ELSE 0 END)+(CASE WHEN jovem.jcomida = mentor.mcomida THEN 1 ELSE 0 END)+(CASE WHEN jovem.jmusica = mentor.mcomida THEN 1 ELSE 0 END)+(CASE WHEN jovem.jesporte = mentor.mesporte THEN 1 ELSE 0 END)+(CASE WHEN jovem.jtime = mentor.mtime THEN 1 ELSE 0 END)+(CASE WHEN jovem.jcaracteristica = mentor.mcaracteristica THEN 1 ELSE 0 END)+(CASE WHEN jovem.janimal = mentor.manimal THEN 1 ELSE 0 END)+(CASE WHEN jovem.jlivro = mentor.mlivro THEN 1 ELSE 0 END)+(CASE WHEN jovem.jsonho = mentor.msonho THEN 1 ELSE 0 END)) AS qtdCaracteristicasIguais FROM jovem INNER JOIN mentor ON jovem.jcidade = mentor.mcidade AND jovem.jestado = mentor.mestado WHERE mentor.mcidade = jovem.jcidade AND mentor.mestado   = jovem.jestado AND mentor.CPF ='$cpf' ORDER BY qtdCaracteristicasIguais DESC LIMIT 2";

$string_sql = "SELECT * FROM mentor WHERE CPF='$cpf'";  



$result= mysqli_query($conexao, $string_sql); 

$resultadojovens = mysqli_query($conexao,$consulta_jovens);

$dado = mysqli_fetch_array($result);    


$nome = $dado['mnome'];     


if(mysqli_affected_rows($conexao)){ 
    echo "<p><h2>Olá, $nome! <br><br> Escolha o seu mentorando abaixo:</h2></p>
    <br>
    <br>
    <p></p>";
    while ($aluno = mysqli_fetch_array($resultadojovens)){

    echo '<header ("content-type: image/jpg")>'.'<b>Foto: </b>'.'<img src='.$aluno['jfoto'].'>'."<br />" .'<b>Nome: </b>'.$aluno['jnome']."<br />".'<b>Faixa Etária: </b> '.$aluno['jfaixaetaria']."<br />".'<b>Escolaridade: </b> '.$aluno['jescolaridade']."<br />" .'<b>Hobby: </b>'.$aluno['jhobby']."<br />".'<b>Comida: </b>'.$aluno['jcomida']."<br />".'<b>Estilo Musical: </b>'.$aluno['jmusica']."<br />" .'<b>Esporte: </b>'.$aluno['jesporte']."<br />".'<b>Time de Futebol:</b> '.$aluno['jtime']."<br />".'<b>Caracteristica:</b> '.$aluno['jcaracteristica']."<br />" .'<b>Animal favorito: </b>'.$aluno['janimal']."<br />".'<b>Livro: </b>'.$aluno['jlivro']."<br />".'<b>Sonho: </b>'.$aluno['jsonho']."<br /> <br />" ;
}

} else {
    echo mysqli_errno($conexao) . ": " . mysqli_error($conexao) . "\n";
}

mysqli_close($conexao); 
?>

</body>
</html>
  • Does the student’s while return the data correctly? If so, is the image path filled in the database? If so, is the link path complete/correct? I believe you don’t need the header image tag on echo...

  • Hello, Darlei. while returns the correct value... I have no image path, I only saved directly in the table.

  • If Voce has not saved the entire image path, you should set the path when echo in the image src, Voce works with a config file?

  • I have a. php file that I get the page information and play in BD.

  • This header ai in the middle of HTML doesn’t make any sense, there are other problems in the code as well. Try to make a [MCVE] without these errors that is simpler to help. The first test would be you access the image directly, or at least make a simpler page, that shows only the direct link to the image for you to click. Once the link works, you pass it to the src

No answers

Browser other questions tagged

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