I'm working with php, js with a data form and upload photos, I want to delete the user's record and at the same time delete the photo with unlink

0

Hi, I'm new with php and I'm working on a form to fill in user data and add a photo, I keep the photo on the server and the path I keep in sql database, what I want is to delete the user record and also delete the server photo, but I can not, I'm using unlink. This is my code to erase

<?php
include "../conexion.php";
$idEmpleado=$_POST['id_cust'];
$queryBuscarFoto="SELECT foto FROM cg_empleados WHERE id_permiso='$idEmpleado'";

    $resultadoBusqueda=mssql_query($queryBuscarFoto); 
    if(mssql_num_rows($resultadoBusqueda)>0)
    {
        while($filaResultado=mssql_fetch_array($resultadoBusqueda,MSSQL_NUM))
        {
          $rutaFoto=$filaResultado[0];
        }

        unlink($rutaFoto);
        $existe=file_exists($rutaFoto);
        if(!$existe)
        {
            //si no existe, se borro correctamente
            $queryBorrar="DELETE from cg_empleados WHERE id_permiso='$idEmpleado'";
            $resultadoBorrar=mssql_query($queryBorrar);
            if($resultadoBorrar)
            {
                // echo "1";
                $resultado['result']=1;
            }
            else
            {   
                //significa que se borro la imagen pero el registro no se borro
                // echo "0";
                $resultado['result']=0;
            }
        }
        else
        {
            //significa que no se borro
            //echo "0";
            $resultado['result']=0;
        }
    }
    else
    {
        //significa que hizo la primera busquedas
        //echo "0";
        $resultado['result']=0;
    }

echo json_encode($resultado);


?>

And this marks me when I try to delete the photo photos / lady-gaga-1.jpg null And this error in console SyntaxError: JSON.parse: unexpected keyword at line 1 column 1 of the JSON data I hope you can help me

    
asked by Lili 04.10.2018 в 21:53
source

0 answers