Save report form

1

This form has been removing gray hair for a few hours and I can not find the reason why it is not saved.

I have the following PHP code, which I use to save a form in the DB

 <?php
 session_start();
 $conexion = mysqli("localhost","root","","cbtahd");
 if(!isset($_SESSION["user"])){
 if(!isset($_POST["guardarReporte"])){
 $emisor = $_POST["emisor"];
 $sucursal = $_POST["sucursal"];
 $area = $_POST["area"];
 $ip = $_POST["ip"];
 $extension = $_POST["extension"];
 $receptor = $_POST["receptor"];
 $reporte = $_POST["reporte"];
 $fechaemi = $_POST["fechaemi"];    
 $email = $_SESSION["user"];
 $insertar = "INSERT INTO tblreportes (emisor,sucursal,area,ip,extension,receptor,reporte,fechaEmi,email) VALUES ('$emisor', '$sucursal','$area','$ip','$extension','$receptor','$reporte','$fechaemi','$email')";
mysqli_query($insertar);
}
}
?>

The html part is the following

<form method="post" action="registrar.php">
        <h1><p class="text-center">Crear reporte</p></h1>
        <br>
        <div class="form-group">
          <label for="emisor">Emisor</label>
          <input type="text" name="emisor" id="emisor" class="form-control">
        </div>

        <div class="form-group">
          <label for="sucursal">Sucursal</label>
          <input type="text" name="sucursal" id="sucursal" class="form-control">
        </div>

        <div class="form-group">
          <label for="area">Area</label>
          <input type="text" name="area" id="area" class="form-control">
        </div>

        <div class="form-group">
          <label for="ip">IP</label>
          <input type="text" name="ip" id="ip" class="form-control">
        </div>

        <div class="form-group">
          <label for="extension">Extension</label>
          <input type="text" name="extension" id="extension" class="form-control">
        </div>

        <div class="form-group">
          <label for="receptor">Receptor</label>
          <input type="text" name="receptor" id="receptor" class="form-control">
        </div>

        <div class="form-group">
          <label for="reporte">Reporte</label>
          <textarea class="form-control" id="reporte" name="reporte" rows="10" cols="50"></textarea>
        </div>

          <div class="form-group">
          <label for="fechaEmi">Fecha de emision</label>
          <input type="text" name="fechaemi" id="fechaemi" class="form-control">
        </div>

        <div class="form-group">
        <a href="logout.php">ffgfgfgdg</a>
          <input type="button" name="guardarReporte" id="guardarReporte" value="Enviar Reporte" class="btn btn-info">
        </div>
        <span id="result"></span>
      </form>

When I put the sentence in the Workbench it records the data correctly.

    
asked by Guillermo Perez 25.07.2016 в 02:33
source

1 answer

0

There is at least one problem with code conditionals that will cause the insert statement to never run:

if(!isset($_POST["guardarReporte"])){

In your form, the button to send the data is this:

<input type="button" name="guardarReporte" id="guardarReporte" value="Enviar Reporte" class="btn btn-info">

Therefore, whenever the form is submitted, guardarReporte will be in the list of past parameters and the conditional will not be fulfilled and nothing will be inserted. I should go without the denial:

if(isset($_POST["guardarReporte"])){

And you may have to do the same with the first if because I do not know if it makes much sense to insert it if the user is not logged in.

    
answered by 25.07.2016 / 03:32
source