0

I am working with php and mysql database. I need to find some car parts with a reference (this is working) in my database , and I also try to get a picture with a specific location were the reference is located.

Here you put the reference:

enter image description here

The problem is when U want to introduce automatically the picture in that reference without manually changing it in my code. What I am looking for is $variable like $busqueda who is storing the number (reference) to be accessible in all files.

I tried $_REQUEST, global, almost anything.

For example:

$sql="UPDATE fiber SET imagen ='$nombre_imagen' where referencia = '$busqueda' "; 

this is working :

$sql="UPDATE fiber SET imagen ='$nombre_imagen' where referencia = '31100001280' "; 

enter image description here

I will paste the code:

This is the first form for searching the car part:

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title> Documento Sin titulo </title>
    <style>
        table{
        margin: auto;
        width: 450px;
        border: 2px dotted goldenrod;
        padding: 30px;
    }
    form{
        margin: auto;
        width: 450px;
        border: 2px dotted goldenrod;
        padding: 30px;
    }
    </style>
</head>
<body>
   <form action="pagina_resultados_act.php" method="get">
        <label>Buscar: <input type="text" name="buscar"></label>
        <input type="submit" name="enviando" value="Dale!">
    </form>

    <!--  Formulario para subir imagenes Prueba 1 12/07/21 
    <form action="busqueda.php" method="POST" enctype="multipart/form-data">

<table>
<tr>
<td><label for="imagen">Imagen:</label></td>
<td><input type="file" name="imagen" size="20"></td>
</tr>
<tr>
    <td colspan="2" style="text-align: center"><input type="submit" value="Enviar Imagen"></td>
</tr>
</table>-->
    
</body>
</html>

Second page:

<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">


</style>
<title> Documento Sin titulo </title>
</head>
<body>

<?php

//mas imagenes en un mismo registro
/*https://es.stackoverflow.com/questions/302794/c%C3%B3mo-cargar-m%C3%A1s-de-una-im%C3%A1gen-en-un-mismo-registro-de-mysql-usando-php*/

$busqueda = $_REQUEST['buscar'];
//$busqueda=$_GET["buscar"];
var_dump($busqueda);

require("datosConexion.php");
$conexion=mysqli_connect($db_host,$db_usuario,$db_contra,$db_nombre,"3308");
//$conexion = mysqli_connect($db_host,$db_usuario,$db_contra,$db_nombre,"3308"); 
if(mysqli_connect_errno()){
    echo "tienes un error en la base de datos";
    exit();
};

mysqli_select_db($conexion,$db_nombre) or die ("No se sencuentra la BBDD");// por si hay error en la conexion ;
mysqli_set_charset($conexion, "utf8");//incluir caracteres latinos

$consulta="SELECT distinct * FROM fiber where referencia LIKE '%$busqueda%'";
$resultados=mysqli_query($conexion, $consulta);

if($fila=mysqli_fetch_array($resultados ,MYSQLI_ASSOC )){
  //echo "<table><tr><td>"; //hoy ya no se usa esto , ahora usamos CSS
  /*echo "<form action='Actualizar.php' method='get'>";
  echo "<input type='text' name='c_art' value='" . $fila["CÓDIGOARTÍCULO"] . "'><br>";
  echo "<input type='text' name='n_art' value='" . $fila["referencia"] . "'><br>";
  echo "<input type='text' name='seccion' value='" . $fila["SECCIÓN"] . "'><br>";
  echo "<input type='text' name='importado' value='" . $fila["PRECIO"] . "'><br>";
  echo "<input type='text' name='precio' value='" . $fila["IMPORTADO"] . "'><br>";
  echo "<input type='text' name='fecha' value='" . $fila["FECHA"] . "'><br>";
  echo "<input type='text' name='p_orig' value='" . $fila["PAÍSDEORIGEN"] . "'><br>";
  echo "<input type='submit' name='enviando' value='Actualizar!'>";
  echo "</form>";*/
  echo $fila["referencia"] . "  " . "</td><td>";
  echo $fila["descripcion"] . " " . "</td><td>";
  echo $fila["ref_caja"] . "  " . "</td><td>";
  echo $fila["medidas"] . "  " . "</td><td>";
  echo $fila["tipo_rack"] . "   " . "</td><td>";
  echo $fila ["ppc"] . "  " . "</td></tr></table>";
}else{
  echo " registro no existe";
}

mysqli_close($conexion);
?>

<br><br>
<form action="subirImagen2.php" method="post" enctype="multipart/form-data">

<table>
<tr>
<td><label for="imagen">Imagen:</label></td>
<td><input type="file" name="imagen" size="50"></td>
</tr>
<tr>
    <td colspan="2" style="text-align: center"><input type="submit" value="Enviar Imagen"></td>
</tr>
</table>
</body>
</html>

And finally the page were I need the form input text number to do the trick:

<?php
$busqueda=$_GET["buscar"];
var_dump($busqueda);

$nombre_imagen=$_FILES['imagen']['name'];
$tipo_imagen=$_FILES['imagen']['type'];//guardar el tipo de imagen en ['type'];
$tamagno_imagen=$_FILES['imagen']['size'];//guardar el tamano en ['size'];
//echo 'tamaño de la imagen ' . $_FILES['imagen']['size'] . ' kb ' . '<br>'; //imprime en pantalla el tamaño de la imagen*/
// dar un tamaño del archivo , que se cumpla solo si queremos que sea asi , en kb

if($tamagno_imagen<=5000000){

  // tamagno imagen de 5mb 
  // podemos dar el tipo de archivo que queramos permitir

  if($tipo_imagen=="image/jpeg" || $tipo_imagen=="image/jpg" || $tipo_imagen =="image/png" || $tipo_imagen == "image/gif" ){

    // indicar el directorio o carpeta dnd queremos guardar la imagen;
    $carpeta_destino=$_SERVER['DOCUMENT_ROOT'] . '/intranet/uploads/'; // teniendo en cuenta que trabajamos en local // ['DOCUMENT_ROOT'] ruta de la carpeta destino //

    // movemos la imagen  desde la carpeta temporal a la carpeta destino 

    //['tmp_name'] nombre de la carpeta temporal dnd se guardara el archivo 

    move_uploaded_file( $_FILES['imagen']['tmp_name'],$carpeta_destino.$nombre_imagen );

  }else{

    echo " solo se pueden subir imagenes jpg,jpeg,png,gif";

  }
}else{
  echo "el tamaño es demasiado grande" ;
}
?>

And here is the error: enter image description here

ADyson
  • 57,178
  • 14
  • 51
  • 63

0 Answers0