Error Insert Database with php

0

Good morning

I'm trying to make an insert to a database from php. It does not give me any apparent failure but it is not able to insert new rows in the table. This is the code. data2.php

if($_POST['add'] == 1) {
    echo "Add";
    $sql = "INSERT INTO noticias (id, name, description, img, show) VALUES (:id, :name, :description, :img, :show)";
    $query = $db->prepare( $sql );
    $imgfile="http://placehold.it/140x120/";
    $image=$_FILES['image']['name'];
    echo "Add";
    if ($image){
        echo "imagen";
        $extension = getExtension($image);
        $extension = strtolower($extension);
        if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) {
            echo "Invalid file type";
        } else {
            /*$size=filesize($_FILES['image']['tmp_name']);
            if ($size > MAX_SIZE*1024) {
                echo "File size error";
            } else {
                $temp=resizeImage($_FILES['image']['tmp_name'],140,120);*/
                $filename = $url.".".$extension;
                $imgfile="./assets/img/noticias/".$filename;
                imagejpeg ( $temp, $imgfile );

        }
    }
    $id=NULL;
    //echo "fueraimagen";
    if ($_POST['enabled'] == "on") {
        $show = 1;
    } else {
        $show = 0;
    }

        $query->execute( array( 
                            ':id'=>$id,
                            ':name'=>$_POST['name'],
                            ':description'=>$_POST['description'],
                            ':img'=>$imgfile,
                            ':show'=>$show ) );
    echo "query";
    foreach($db->query ("SELECT MAX(id) AS id FROM noticias") as $row) {
        $id=$row['id'];
    }
    echo ($id);
    //echo ($form_data['convs']);
    header('Location: panel.php');

} 

This is the database

And so I send information from the html, panel.php

  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#añadirCurso">Añadir Noticia</button>

<div class="modal fade" id="añadirCurso" role="dialog">
<div class="modal-dialog">
  <form enctype="multipart/form-data" role="form" method="post" action="data2.php">
    <input type="hidden" name="add" id="add" value="1">   
    <input type="hidden" name="mod" id="mod" value="0">
    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Añadir Noticia</h4>
      </div>
      <div class="form-group">
          <label for="name">Nombre</label>
          <input type="text" class="form-control" id="name" name="name" value="" placeholder="Nombre de la noticia">
      </div>
      <div class="form-group">
          <label for="description">Descripción</label>
          <textarea class="form-control rte-zone" name="description" id="description" placeholder="Descripción de la noticia" rows="3"></textarea>
      </div>
      <div class="form-group">
          <label for="image">Imagen</label>
          <input type="file" id="image" name="image">
      </div>
      <div class="checkbox">  
          <input type="checkbox" id="enabled" name="enabled" checked><label for="enabled">Mostrar noticia</label>
      </div>
      <div class="modal-footer">
        <button type="submit" class="btn btn-default">Enviar</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
      </div>
    </div>
  </form>

</div>

    
asked by CMorillo 28.08.2017 в 13:19
source

0 answers