Does not write data with MySql

-2

Well guys, I have the following complication, every patient has a called "PII" and that same "PII" has several data. The problem is when filling in the PII when clicking on record it simply clears me all the data instead of storing it in the database.

The initial excerpt of php connecting to MySql:

    <?php
session_start();
error_reporting(0);
include('includes/config.php');
if(strlen($_SESSION['alogin'])==0)
    {   
header('location:index.php');
}
else{
if(isset($_POST['add']))
{
$avinicial=$_POST['AvInicial'];
$meta=$_POST['Meta'];
$avintercalar=$_POST['AvIntercalar'];
$avfinal=$_POST['AvFinal'];
$datainicio=$_POST['DataInicio'];
$datafim=$_POST['DataFim'];
$resultadouni=$_POST['ResultadoUni'];
$avalexp=$_POST['AvalExpec'];
$concretizaobj=$_POST['ConcretizaObj'];
$objdefinidos=$_POST['ObjDefinidos'];
$objatingidos=$_POST['ObjAtingidos'];
$totalalcancados=$_POST['TotalAlcancados'];
$sql = "INSERT INTO tblobjetivos(AvInicial, Meta, AvIntercalar, AvFinal, DataInicio, DataFim, ResultadoUni, AvalExpec, ConcretizaObj, ObjDefinidos, ObjAtingidos, TotalAlcancados) VALUES(:avinicial, :meta, :avintercalar, :avfinal, :datainicio, :datafim, :resultadouni, :avalexp, :concretizaobj, :objdefinidos, :objatingidos, :totalalcancados)";
$query = $dbh->prepare($sql);
$query->bindParam(':avinicial', $avinicial, PDO::PARAM_STR);
$query->bindParam(':meta', $meta, PDO::PARAM_STR);
$query->bindParam(':avintercalar', $avintercalar, PDO::PARAM_STR);
$query->bindParam(':avfinal', $avfinal, PDO::PARAM_STR);
$query->bindParam(':datainicio', $datainicio, PDO::PARAM_STR);
$query->bindParam(':datafim', $datafim, PDO::PARAM_STR);
$query->bindParam(':resultadouni', $resultadouni, PDO::PARAM_STR);
$query->bindParam(':avalexp', $avalexp, PDO::PARAM_STR);
$query->bindParam(':concretizaobj', $concretizaobj, PDO::PARAM_STR);
$query->bindParam(':objdefinidos', $objdefinidos, PDO::PARAM_STR);
$query->bindParam(':objatingidos', $objatingidos, PDO::PARAM_STR);
$query->bindParam(':totalalcancados', $totalalcancados, PDO::PARAM_STR);
$lastInsertId = $dbh->lastInsertId();
$query->execute();

    if ($lastInsertId) {
        $msg = "PII Adicionado com Sucesso";
    } else {
        $error = "Confirme se preencheu tudo corretamente!";
    }
}?>

    
asked by anonymous 09.09.2018 / 16:01

1 answer

-1

Not a solution but a tip: in the connection file (probably /include/config.php), configure the PDO to trigger exceptions. These exceptions will contain important information, such as why the data is not being persisted at the bank. For example, if a column is NOT NULL in the database and you are trying to add a null value, it will raise an exception with the message.

link

<?php
$dsn = 'mysql:dbname=testdb;host=127.0.0.1';
$user = 'dbuser';
$password = 'dbpass';

try {
    $dbh = new PDO($dsn, $user, $password);
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}

?>

I hope I have helped.

    
10.09.2018 / 03:10