-1

I'm developing a project Personl and I have encountered a problem.

Details my of problem

Perform a query via a form, which calls me to another page where the query is displayed, everything is correct, it displays the information that I need, but when viewing the user's image, calling me by request the ID corresponding to this user, but not my image code is displayed below.

Code to display the image in html:

<img src="../../registro/imagen.php?matricula=<?php echo $_POST['matricula']; ?>" width="150px" height="150px" />

Code search the image by id to display:

 <?php
$numero=$_REQUEST['matricula'];
$tabla="alumno";
include("../../Connections/colegio.php");
$conexion=@mysqli_connect($hostname_colegio,$username_colegio,$password_colegio,$database_colegio);
    $sacar = "SELECT * FROM ".$tabla." WHERE (matricula=$numero)" ;
    $resultado = mysqli_query($conexion,$sacar);
while ($registro = mysqli_fetch_assoc($resultado))echo mysqli_error( $conexion );{
            $tipo_foto=$registro['matricula'];
             header("Content-type: image/jpg");
             echo $registro['matricula'];
}



mysqli_close($conexion);
?>
Community
  • 1
  • 1
  • 1
    Why are you suppressing errors? – Jay Blanchard Oct 13 '15 at 16:31
  • Forgive but do not understand your question, you can guide me please – Alexander Quiroz Oct 13 '15 at 16:37
  • Remove @ symbol in your connection string – Subin Thomas Oct 13 '15 at 16:39
  • Thanks Subin Thomas, I have removed the @, but still, the image is not displayed – Alexander Quiroz Oct 13 '15 at 16:46
  • http://stackoverflow.com/questions/1032161/what-is-the-use-of-symbol-in-php Read this @user2766089 – Subin Thomas Oct 13 '15 at 16:49
  • Add error reporting to the top of your file(s) right after your opening PHP tag for example ` – Funk Forty Niner Oct 13 '15 at 16:55
  • this line is causing you trouble `while ($registro = mysqli_fetch_assoc($resultado))echo mysqli_error( $conexion );{` for a few reasons. – Funk Forty Niner Oct 13 '15 at 16:57
  • hi thanks again, I removed the @ to display the error, which apparently have to capture, to know which is the call from the browser "../../registro/imagen.php?matricula=" in the browser only show me the broken image icon, any suggestions please? – Alexander Quiroz Oct 13 '15 at 17:01
  • simple, remove this `echo mysqli_error( $conexion );` from `while ($registro = mysqli_fetch_assoc($resultado))echo mysqli_error( $conexion );{` – Funk Forty Niner Oct 13 '15 at 17:11
  • thanks Fred, for you support, went back to search with ID 2015051439 in my database and the photo that corresponds to the same ID, this , the result of this search is "" brings me, the id command to seek enrollment, but not I add the .jpg format, and the image is broken, if I type the full path 2015051439.jpg adding at the end, I get the same broken image. – Alexander Quiroz Oct 13 '15 at 17:19
  • **WARNING**: When using `mysqli` you should be using parameterized queries and [`bind_param`](http://php.net/manual/en/mysqli-stmt.bind-param.php) to add user data to your query. **DO NOT** use string interpolation or concatenation to accomplish this because you will create severe [SQL injection bugs](http://bobby-tables.com/). **NEVER** put `$_POST` or `$_REQUEST` data directly into a query. – tadman Oct 13 '15 at 17:29
  • Thanks Tadman, you can suggest me change, excuse my ignorance but I am newbie in php. – Alexander Quiroz Oct 13 '15 at 17:37

1 Answers1

0

may terminate this issue, if it helps someone, I leave the correct code.

    <?php  
$numero=$_REQUEST['matricula'];
  $consulta="select * from alumno WHERE (matricula = $numero)";
  $busca_fotos=mysql_query($consulta) or die("Error en: $busca_fotos:" .mysql_error()) ;
  while($ro=mysql_fetch_assoc($busca_fotos)){
   $url=$ro['matricula'];  

     echo  "
                <img src=\"../../registro/fotos/".$url.".jpg\" width=\"150\" height=\"150\" alt=\"\" />

            </a>
       ";
  }
?>