Image not saved well in BD php

0

I am migrating to use functions, insert the image but it does not recover it, in the previous normal code it inserts and recovers, it can be said that the image was collected like this:

$foto1 = $mysqli->real_escape_string(base64_decode($_REQUEST['foto1']));

Code with function:

<?php
function registrarDocente($nombre1,$apellidop1,$apellidom1,$correo1,$sexo1,$foto1, $codigo1,$password,$doc,$telefono1,$fecha1,$tdocumento1,$documento1){
global $mysqli;
$stmt = $mysqli->prepare("INSERT INTO usuarios nombres,apellidop,apellidom,foto,correo,tdoc,ndoc,user,password,tipo,genero,ntelefono,fnacimiento) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
$stmt-> bind_param('sssssiiisiiis',$nombre1,$apellidop1,$apellidom1,$foto1,$correo1,$tdocumento1,$documento1,$codigo1,$password,$doc,$sexo1,$telefono1,$fecha1);
if($stmt->execute()){
    $data[]=array('mensaje'=> 'Docente registrado con exito');
    echo json_encode($data);
}
}
?>

Previous code:

if ($verificacion1=='1D') {
//Sentencia, insertar registro.
if (mysqli_query($con,"INSERT INTO usuarios (nombres,apellidop,apellidom,foto,correo,tdoc,ndoc,user,password,tipo,genero,ntelefono,fnacimiento) 
    VALUES ('".$nombre1."','".$apellidop1."','".$apellidom1."','".$foto1."','".$correo1."','".$tdocumento1."','".$documento1."','".$codigo1."','".$password."',
    '".$doc."','".$sexo1."','".$telefono1."','".$fecha1."')")){
    $data[]=array('mensaje'=> 'Docente registrado con exito');
    echo json_encode($data);
}else{
    $data[]=array('mensaje'=> 'Docente no registrado');
    echo json_encode($data);
}
    
asked by Rodolfo Gav 22.05.2017 в 17:23
source

1 answer

0

What error appears to you? As a good practice, it is recommended that when you enter the image, move it to a folder, so that your database does not become too heavy, leaving only the name of the image and its extension in the database

An example to which I refer is the following:

$thumb_guardada = $_POST['thumb-guardada'];
$thumb = $_FILES['thumb'];
        if (empty($thumb['name'])) {
            $thumb = $thumb_guardada;
        } else {
            $archivo_subido = 'images/' . $_FILES['thumb']['name'];
            move_uploaded_file($_FILES['thumb']['tmp_name'], $archivo_subido);
            $thumb = $_FILES['thumb']['name'];
        }

        $errores = '';
        $success = '<li>Los datos se reflejaran cuando vuelvas a iniciar sesion</li>';

            try {
                $conexion = new PDO('mysql:host=localhost;dbname=empleos', 'root', '');
            } catch (PDOException $e) {
                echo "Error: " . $e->getMessage();
            }

            $statement = $conexion->prepare('UPDATE userslog SET thumb = :thumb WHERE id = :id');

            if (!empty($errores)) {

                $statement->execute(array(
                    ':id' => $id,
                    ':thumb' => $thumb
                ));

thumb save the use in an input type hidden where I bring the name of the iamgen in case the user does not change it

    
answered by 22.05.2017 в 20:16