Information is not inserted in the database

2020-04-01 php html mysql forms

I'm doing a submit form on php connected to mysql, using the Xammp administrator When I push the "Submit" button, this don't do anything, practically, just reload the page with the characters I put in the fields

Here's the code

<?php
// Include config file
require_once "config.php";

// Define variables and initialize with empty values
$Sem = $fs = $regist = $DesAmb = $ippms = $AudCal = $EntrTiem = $efic = $SugPro = $ActPiz = $Cert = $Ausen = $Scrap = $Retrab = $Audimttoaut = $OEE = "";
$Sem_err = $fs_err = $regist_err = $DesAmb_err = $ippms_err = $AudCal_err = $EntrTiem_err = $efic_err = $SugPro_err = $ActPiz_err = $Cert_err = $Ausen_err = $Scrap_err = $Retrab_err = $Audimttoaut_err = $OEE_err = "";

// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
    // Validate Semana = $Sem
    $input_Sem = trim($_POST["Sem"]);
    if(empty($input_Sem)){
        $Sem_err = "Captura el numero de la semana en curso.";
    } elseif(!ctype_digit($input_Sem)){
        $Sem_err = "Solo ingresa numeros.";
    } else{
        $Sem = $input_Sem;
    }

    // Validate 5's = $fs
    $input_fs = trim($_POST["fs"]);
    if(empty($input_fs)){
        $fs_err = "Captura el metrico de 5's.";
    } elseif(!ctype_digit($input_fs)){
        $fs_err = "Solo ingresa numeros.";
    } else{
        $fs = $input_fs;
    }

    // Validate regitrables = $regist
    $input_regist = trim($_POST["regist"]);
    if(empty($input_regist)){
        $regist_err = "Captura el metrico de registrables.";     
    }elseif(!ctype_digit($input_regist)){
        $regist_err = "Solo ingresa numeros.";
    } else{
        $regist = $input_regist;
    }

    // Validate Desempeño ambiental = $DesAmb
    $input_DesAmb = trim($_POST["DesAmb"]);
    if(empty($input_DesAmb)){
        $salary_err = "Captura el metrico para Desempeño ambiental.";     
    } elseif(!ctype_digit($input_DesAmb)){
        $DesAmb_err = "Solo ingresa numeros.";
    } else{
        $DesAmb = $input_DesAmb;
    }

      // Validate IPPM's = $ippms
    $input_ippms = trim($_POST["ippms"]);
    if(empty($input_ippms)){
        $ippms_err = "Captura el metrico para IPPM's.";
    } elseif(!ctype_digit($input_ippms)){
        $fs_err = "Solo ingresa numeros.";
    } else{
        $ippms = $input_ippms;
    }

    // Validate Auditoria de calidad = $AudCal
    $input_AudCal = trim($_POST["AudCal"]);
    if(empty($input_AudCal)){
        $AudCal_err = "Captura el metrico para Auditoria de calidad.";     
    } elseif(!ctype_digit($input_AudCal)){
        $AudCal_err = "Solo ingresa numeros.";
    }else{
        $AudCal = $input_AudCal;
    }

    // Validate Entregas a tiempo = $EntrTiem
    $input_EntrTiem = trim($_POST["EntrTiem"]);
    if(empty($input_EntrTiem)){
        $EntrTiem_err = "Captura el metrico de Entregas a tiempo.";     
    } elseif(!ctype_digit($input_EntrTiem)){
        $EntrTiem_err = "Solo ingresa numeros.";
    } else{
        $EntrTiem = $input_EntrTiem;
    }

      // Validate Eficiencia = $efic
    $input_efic = trim($_POST["efic"]);
    if(empty($input_efic)){
        $efic_err = "Captura el metrico de Eficiencia.";
    } elseif(!ctype_digit($input_efic)){
        $efic_err = "Solo ingresa numeros.";
    } else{
        $efic = $input_efic;
    }

    // Validate Sugerencias propuestas = $SugPro
    $input_SugPro = trim($_POST["SugPro"]);
    if(empty($input_SugPro)){
        $SugPro_err = "Captura el metrico de Sugerencias propuestas.";     
    } else{
        $SugPro = $input_SugPro;
    }

    // Validate Actualizacion de pizarrones = $ActPiz
    $input_ActPiz = trim($_POST["ActPiz"]);
    if(empty($input_ActPiz)){
        $ActPiz_err = "Captura el metrico para Actualizacion de pizarrones.";     
    } elseif(!ctype_digit($input_ActPiz)){
        $ActPiz_err = "Solo ingresa numeros.";
    } else{
        $ActPiz = $input_ActPiz;
    }

      // Validate Certificaciones = $Cert
    $input_Cert = trim($_POST["Cert"]);
    if(empty($input_Cert)){
        $Cert_err = "Captura el metrico de Certificaciones.";
    }elseif(!ctype_digit($input_Cert)){
        $Cert_err = "Solo ingresa numeros.";
    } else{
        $Cert = $input_Cert;
    }

    // Validate Ausentismo = $Ausen
    $input_Ausen = trim($_POST["Ausen"]);
    if(empty($input_Ausen)){
        $Ausen_err = "Captura el metrico para Ausentismo.";     
    }elseif(!ctype_digit($input_Ausen)){
        $Ausen_err = "Solo ingresa numeros."; 
    }else{
        $Ausen = $input_Ausen;
    }

    // Validate Scrap = $Scrap
    $input_Scrap = trim($_POST["Scrap"]);
    if(empty($input_Scrap)){
        $Scrap_err = "Captura el metrico para Scrap.";     
    } elseif(!ctype_digit($input_Scrap)){
        $Scrap_err = "Solo ingresa numeros.";
    } else{
        $Scrap = $input_Scrap;
    }

      // Validate Retrabajo = $Retrab
    $input_Retrab = trim($_POST["Retrab"]);
    if(empty($input_Retrab)){
        $Retrab_err = "Captura el metrico para Retrabajo.";
    } elseif(!ctype_digit($input_Retrab)){
        $Retrab_err = "Solo ingresa numeros.";
    } else{
        $Retrab = $input_Retrab;
    }

    // Validate Auditoria de mantenimiento autonomo = $Audimttoaut
    $input_Audimttoaut = trim($_POST["Audimttoaut"]);
    if(empty($input_Audimttoaut)){
        $Audimttoaut_err = "Captura el metrico para Auditoria de mantenimiento autonomo.";     
    } elseif(!ctype_digit($input_Audimttoaut)){
        $Audimttoaut_err = "Solo ingresa numeros."; 
    } else{
        $Audimttoaut = $input_Audimttoaut;
    }

    // Validate OEE =$OEE
    $input_OEE = trim($_POST["OEE"]);
    if(empty($input_OEE)){
        $OEE_err = "Captura el metrico para OEE.";     
    } elseif(!ctype_digit($input_OEE)){
        $OEE_err = "Solo ingresa numeros.";
    } else{
        $OEE = $input_OEE;
    }

    // Check input errors before inserting in database
    if(empty($Sem_err) && empty($fs_err) && empty($regist_err) && empty($DesAmb_err) && empty($ippms_err) && empty($AudCal_err) && empty($EntrTiem_err) && empty($efic_err) && empty($SugPro_err) && empty($Actpiz_err) && empty($Cert_err) && empty($Ausen_err) && empty($Scrap_err) && empty($Retrab_err) && empty($Audimttoaut_err) && empty($OEE_err)){
        // Prepare an insert statement
        $sql = "INSERT INTO `jc500` (`Semana`, `5's`, `Registrables`, `Desempeño ambiental`, `IPPM's`, `Auditoria Calidad`, `Entregas a tiempo`, `Eficiencia`, `Sugerencias propuestas`, `Actualizacion de pizarrones`, `Certificaciones`, `Ausentismo`, `Scrap`, `Retrabajo`, `Auditoria mantenimiento autonomo`, `OEE`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" or die (mysqli_error());

        if($stmt = mysqli_prepare($link, $sql)){
            // Bind variables to the prepared statement as parameters
            mysqli_stmt_bind_param($stmt, "ssssssssssssssss", $param_Sem, $param_fs, $param_regist, $param_DesAmb, $param_ippms, $param_AudCal, $param_EntrTiem, $param_efic, $param_SugPro, $param_ActPiz, $param_Cert, $param_Ausen, $param_Scrap, $param_Retrab, $param_Audimttoaut, $param_OEE);

            // Set parameters
            $param_Sem = $Sem;
            $param_fs = $fs;
            $param_regist = $regist;
            $param_DesAmb = $DesAmb;
            $param_ippms = $ippms;
            $param_AudCal = $AudCal;
            $param_EntrTiem = $EntrTiem;
            $param_efic = $efic;
            $param_SugPro = $SugPro;
            $param_ActPiz = $ActPiz;
            $param_Cert = $Cert;
            $param_Ausen = $Ausen;
            $param_Scrap = $Scrap;
            $param_Retrab = $Retrab;
            $param_Audimttoaut = $Audimttoaut;
            $param_OEE = $OEE;
            // Attempt to execute the prepared statement
            if(mysqli_stmt_execute($stmt)){
                // Records created successfully. Redirect to landing page
                 echo "<div class='alert alert-success'>Record was saved.</div>";
                header("location: inicio.php");
                exit();

            } else {
                echo mysqli_error($link) ;
            }
        }

        // Close statement


    }
    // Close connection
    mysqli_close($link);
} 
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JC500</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
    <style type="text/css">
        .wrapper{
            width: 500px;
            margin: 0 auto;
        }
    </style>
</head>
<body>
    <div class="wrapper">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-12">
                    <div class="page-header">
                        <h2>HPT JCI</h2>
                    </div>
                    <p>Pantalla para capturar los metricos del HPT JC500 </p>
                    <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
                        <div class="form-group <?php echo (!empty($Sem_err)) ? 'has-error' : ''; ?>">
                            <label>Numero de semana</label>
                            <input type="text" name="Sem" class="form-control" value="<?php echo $Sem; ?>">
                            <span class="help-block"><?php echo $Sem_err;?></span>
                        </div>
                        <div class="form-group <?php echo (!empty($fs_err)) ? 'has-error' : ''; ?>">
                            <label>5's</label>
                            <input type="text" name="fs" class="form-control" value="<?php echo $fs; ?>">
                            <span class="help-block"><?php echo $fs_err;?></span>
                        </div>
                        <div class="form-group <?php echo (!empty($regist_err)) ? 'has-error' : ''; ?>">
                            <label>Registrables</label>
                            <input type="text" name="regist" class="form-control" value="<?php echo $regist; ?>">
                            <span class="help-block"><?php echo $regist_err;?></span>
                        </div>
                        <div class="form-group <?php echo (!empty($DesAmb_err)) ? 'has-error' : ''; ?>">
                            <label>Desempeño ambiental</label>
                            <input type="text" name="DesAmb" class="form-control" value="<?php echo $DesAmb; ?>">
                            <span class="help-block"><?php echo $DesAmb_err;?></span>
                        </div>
                        <div class="form-group <?php echo (!empty($ippms_err)) ? 'has-error' : ''; ?>">
                            <label>IPPM's</label>
                            <input type="text" name="ippms" class="form-control" value="<?php echo $ippms; ?>">
                            <span class="help-block"><?php echo $ippms_err;?></span>
                        </div>
                        <div class="form-group <?php echo (!empty($AudCal_err)) ? 'has-error' : ''; ?>">
                            <label>Auditoria de calidad</label>
                            <input type="text" name="AudCal" class="form-control" value="<?php echo $AudCal; ?>">
                            <span class="help-block"><?php echo $AudCal_err;?></span>
                        </div>
                        <div class="form-group <?php echo (!empty($EntrTiem_err)) ? 'has-error' : ''; ?>">
                            <label>Entregas a tiempo</label>
                            <input type="text" name="EntrTiem" class="form-control" value="<?php echo $EntrTiem; ?>">
                            <span class="help-block"><?php echo $EntrTiem_err;?></span>
                        </div>
                        <div class="form-group <?php echo (!empty($efic_err)) ? 'has-error' : ''; ?>">
                            <label>Eficiencia</label>
                            <input type="text" name="efic" class="form-control" value="<?php echo $efic; ?>">
                            <span class="help-block"><?php echo $efic_err;?></span>
                        </div>
                        <div class="form-group <?php echo (!empty($SugPro_err)) ? 'has-error' : ''; ?>">
                            <label>Sugerencias propuestas</label>
                            <input type="text" name="SugPro" class="form-control" value="<?php echo $SugPro; ?>">
                            <span class="help-block"><?php echo $SugPro_err;?></span>
                        </div>
                        <div class="form-group <?php echo (!empty($ActPiz_err)) ? 'has-error' : ''; ?>">
                            <label>Actualización de pizarrones</label>
                            <input type="text" name="ActPiz" class="form-control" value="<?php echo $ActPiz; ?>">
                            <span class="help-block"><?php echo $ActPiz_err;?></span>
                        </div>
                        <div class="form-group <?php echo (!empty($Cert_err)) ? 'has-error' : ''; ?>">
                            <label>Certificaciones</label>
                            <input type="text" name="Cert" class="form-control" value="<?php echo $Cert; ?>">
                            <span class="help-block"><?php echo $Cert_err;?></span>
                        </div>
                        <div class="form-group <?php echo (!empty($Ausen_err)) ? 'has-error' : ''; ?>">
                            <label>Ausentismo</label>
                            <input type="text" name="Ausen" class="form-control" value="<?php echo $Ausen; ?>">
                            <span class="help-block"><?php echo $Ausen_err;?></span>
                        </div>
                        <div class="form-group <?php echo (!empty($Scrap_err)) ? 'has-error' : ''; ?>">
                            <label>Scrap</label>
                            <input type="text" name="Scrap" class="form-control" value="<?php echo $Scrap; ?>">
                            <span class="help-block"><?php echo $Scrap_err;?></span>
                        </div>
                        <div class="form-group <?php echo (!empty($Retrab_err)) ? 'has-error' : ''; ?>">
                            <label>Retrabajo</label>
                            <input type="text" name="Retrab" class="form-control" value="<?php echo $Retrab; ?>">
                            <span class="help-block"><?php echo $Retrab_err;?></span>
                        </div>
                        <div class="form-group <?php echo (!empty($Audimttoaut_err)) ? 'has-error' : ''; ?>">
                            <label>Auditoria de mantenimiento autonomo</label>
                            <input type="text" name="Audimttoaut" class="form-control" value="<?php echo $Audimttoaut; ?>">
                            <span class="help-block"><?php echo $Audimttoaut_err;?></span>
                        </div>
                        <div class="form-group <?php echo (!empty($OEE_err)) ? 'has-error' : ''; ?>">
                            <label>OEE</label>
                            <input type="text" name="OEE" class="form-control" value="<?php echo $OEE; ?>">
                            <span class="help-block"><?php echo $OEE_err;?></span>
                        </div>
                        <input type="submit" class="btn btn-primary" value="Submit">
                        <a href="inicio.php" class="btn btn-default">Cancel</a>
                    </form>
                </div>
            </div>        
        </div>
    </div>
</body>
</html>

I don't know why it is not working, it is supposed to show data in the table but it is not showing anything

Answers

Related