Good morning, I'm trying to download a blob image from mysql for an employee form. When downloading it, it shows me the empty field with the first code that I leave below:
<?php
$con = mysql_connect ("sql213.epizy.com","epiz_31980107","l20DHKEhYd");
if (!$con){die ("ERROR AL CONECTAR CON LA BASE DE DATOS ".mysql_error());}
$db = mysql_select_db("epiz_31980107_certificaciones",$con);
if (!$db) {die ("ERROR AL SELECCIONAR DB ".mysql_error());}
//ojo: con la sentencia sql, que es la que
//utilizamos para la consulta a mas de una tabla
$sql = ("SELECT empleado.NoReloj,certificaciones.Certificacion,certificaciones.Fecha_Cert,certificaciones.Fecha_Ven
FROM empleado, certificaciones WHERE empleado.NoReloj='".$_REQUEST['matricula']."' AND certificaciones.empleado_id ='".$_REQUEST['matricula']."'");
//realizamos la consulta
$consulta2= ("SELECT * FROM empleado WHERE empleado.NoReloj='" .$_REQUEST['matricula']."'");
$consuimg= ("SELECT Imagen FROM empleado WHERE empleado.NoReloj='" .$_REQUEST['matricula']."'");
$result2=mysql_query($consulta2);
$resuimg=mysql_query($consuimg);
$result = mysql_query($sql,$con);
if(mysql_num_rows($result2)>0){
if($datos=mysql_fetch_row($result2)){
$matricula2=$datos[0];
$img=$datos[1];
$nombre2=$datos[2];
$apellido1=$datos[3];
$apellido2=$datos[4];
$fecha=$datos[5];
$area=$datos[6];
}
}
?>
<table align="center">
<tr>
<td>Numero de Reloj</td>
<td>Area</td>
</tr>
<tr>
<td><input type="text" name="matricula" value="<?php echo $matricula2; ?>" disabled></td>
<td><input type="text" value="<?php echo $area; ?>" disabled></td>
<img value="<?php echo $img; ?>" />
But when I try it with the code2 that I leave below, it throws me the image as broken that it is not being able to recover it. I would be very grateful if you could help me to know what I am doing wrong.
Thanks in advance
<?php
$con = mysql_connect ("sql213.epizy.com","epiz_31980107","l20DHKEhYd");
if (!$con){die ("ERROR AL CONECTAR CON LA BASE DE DATOS ".mysql_error());}
$db = mysql_select_db("epiz_31980107_certificaciones",$con);
if (!$db) {die ("ERROR AL SELECCIONAR DB ".mysql_error());}
//ojo: con la sentencia sql, que es la que
//utilizamos para la consulta a mas de una tabla
$sql = ("SELECT empleado.NoReloj,certificaciones.Certificacion,certificaciones.Fecha_Cert,certificaciones.Fecha_Ven
FROM empleado, certificaciones WHERE empleado.NoReloj='".$_REQUEST['matricula']."' AND certificaciones.empleado_id ='".$_REQUEST['matricula']."'");
//realizamos la consulta
$consulta2= ("SELECT * FROM empleado WHERE empleado.NoReloj='" .$_REQUEST['matricula']."'");
$consuimg= ("SELECT Imagen FROM empleado WHERE empleado.NoReloj='" .$_REQUEST['matricula']."'");
$result2=mysql_query($consulta2);
$result = mysql_query($sql,$con);
$resimg = mysql_query($consuimg,$con);
if(mysql_num_rows($result2)>0){
if($datos=mysql_fetch_row($result2)){
$matricula2=$datos[0];
$nombre2=$datos[2];
$apellido1=$datos[3];
$apellido2=$datos[4];
$fecha=$datos[5];
$area=$datos[6];
}
}
while($row = mysql_fetch_assoc($resimg)) {
?>
<img src="data:<?php echo base64_encode($row['Imagen']); ?>">
<?php
}
?>
<table align="center">
<tr>
<td>Numero de Reloj</td>
<td>Area</td>
</tr>
<tr>
<td><input type="text" name="matricula" value="<?php echo $matricula2; ?>" disabled></td>
<td><input type="text" value="<?php echo $area; ?>" disabled></td>