Error when modifying a PHP and MYSQLI image

0

I have this code but I'm getting this error ...

<?php
session_start();

$conexion = mysqli_connect("localhost","root","", "trigoyponque2017"); 
/*
$ruta    = $_FILES['foto1']['tmp_name'];
$destino = "../productos/".$_FILES['foto1']['name'];
copy($_FILES['foto1']['tmp_name'],$destino);
$foto  =$_FILES['foto1']['name'];
*/
foreach ($_POST['seleccion'] as $indice => $valor){
//Vamos a verificar si trae la opcion de eliminar o modificar
$opcion = substr ($_POST['seleccion'][$indice],0,-1); //extraemos la parte de la cadena que elimina y/o modifica
switch($opcion){
    case 'modifica':
    if($_FILES['foto1']['name'] == ""){
    $sql= "UPDATE producto SET titulo='".$_POST['titulo'][$indice]."', descripcion='".$_POST['descripcion'][$indice]."' WHERE id=".$_POST['id'][$indice];
    }else{
    $consulta = mysqli_query($conexion, "SELECT * FROM producto WHERE id=".$_POST['id'].";");   
    while ($reg = mysqli_fetch_array($consulta)){
        unlink("../productos/".$reg['foto']);
    }
    $ruta    = "../productos/";
    opendir($ruta);
    $destino = $ruta.$_FILES['foto1']['name'];
    copy($_FILES['foto1']['tmp_name'],$destino);
    $foto   = $_FILES['foto1']['name']; 

    $sql = "UPDATE producto SET titulo='".$_POST['titulo'][$indice]."', descripcion='".$_POST['descripcion'][$indice]."', foto='".$foto[$indice]."' WHERE id=".$_POST['id'][$indice];
    }
    break;

    case 'elimina':
    $sql="DELETE FROM producto WHERE id=".$_POST['id'][$indice];
    break;
    default: echo "<center>NO HAY NADA SELECCIONADO</center>"; break;
}
}
echo "Variable sql: ".$sql;

$resultado = mysqli_query($conexion,$sql);
if (!$resultado ){
     echo ("ERROR AL EJECUTAR LA CONSULTA");
}
else{
    echo "<center>FELICIDADES SENTENCIA EJECUTADA CORRECTAMENTE<br />
    <a href='editar_producto.php'><input type='button' value='Volver'></a></center>";
}


mysqli_close($conexion);
?>

I do not know why you can not find the route if I'm defining it there ...

    
asked by Sercroft1 04.10.2017 в 22:07
source

1 answer

0

Regards

Apparently the line 19 that tells you in the first notice is:

$consulta = mysqli_query($conexion, "SELECT * FROM producto WHERE id=".$_POST['id'].";");

I see that in the previous UPDATE line:

$sql= "UPDATE producto SET titulo='".$_POST['titulo'][$indice]."', descripcion='".$_POST['descripcion'][$indice]."' WHERE id=".$_POST['id'][$indice];

what is $_POST['id'] you refer to it with an index value; even here it is an array $_POST['id'] because in that case it is what you need to indicate as in UPDATE .

    
answered by 04.10.2017 в 22:21