Problem when loading image to BD in MySQL

1

I have a problem with uploading the image to BD MySQL! The process is carried correctly until the image of the user's computer is uploaded to my server, but after that, the statement that is responsible for saving values in the database is not executed. If I check the folder where the uploaded images are saved, there is the image, but never a record is inserted in the BD ...

This is the HTML code

<?php require 'headerAdministratorVistas.php'; ?>

<div class="contenedor"> 

    <div class="slideshow">

    <article>
    <br/><br/>
    <div class="posttitle">
        <img src="../images/titleinfoConta.png">
    </div>
    <hr>
    </article>  

    <article>
    <br/>
    <form class="formularioEditar" method="post" enctype="multipart/form-data" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
        <input type="text" name="concepto" class="contentinfo" placeholder="Forma de Contacto"><br/><br/>
        <input type="text" name="informacion" class="contentinfo" placeholder="Descripción"><br/><br/>
        <input type="file" name="imagen">
        <input type="submit" value="Crear nueva Categoría" class="guardarcambios">
    </form>


    </article>

    </div>
</div>

<?php require 'footer.php'; ?>

Y este, el código PHP

    <?php session_start();

require 'config.php';
require '../functions.php';

comprobarSesion();

$conexion = conexion($bd_config);

if (!$conexion) {
    header('Location: ../error.php');
}

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $concepto = $_POST['concepto'];
    $informacion = $_POST['informacion'];
    $imagen = $_FILES['imagen']['tmp_name'];

    $archivo_asubir = '../' . $pagina_config['carpeta_imagenes'] . $_FILES['imagen']['name'];
    move_uploaded_file($imagen, $archivo_asubir);

    $statement = $conexion->prepare(
    'INSERT INTO contacto (id, concepto, informacion, image)
    VALUES (null, :concepto, :informacion, :imagen)'
    );

    $statement->execute(array(
    ':concepto' => $concepto,
    ':informacion' => $informacion,
    ':imagen' => $_FILES['imagen']['name']
    ));

   header('Location: '. RUTA . 'admin/mostrarContacto.php');

}

require '../views/nuevoContacto.view.php';  ?>
    
asked by Cesar Esparza Vera 25.10.2016 в 05:55
source

2 answers

0

Try checking if the INSERT generated an error using errorInfo .

Add these lines below the execute :

$arr = $statement->errorInfo();
print_r($arr);
die();
    
answered by 25.10.2016 / 14:09
source
0

Try changing your query, you can not insert a value in the data base specifying that id is null

If you do not want to manually specify the id just ignore it in your statement.

$statement = $conexion->prepare(
' INSERT INTO contacto (concepto, informacion, image)
  VALUES (:concepto, :informacion, :imagen)'
);
    
answered by 25.10.2016 в 08:43