How to get the POST value and save it to the bank

0

View image:

ImageoftheBank

Code

$nome_plano=trim($_POST["nome_plano"]);
    $quemcadastrou = $userRow['nome_funcionario'];

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      $conn->beginTransaction();
      $conn->exec("INSERT INTO plano (nome_plano, quemcadastrou, data_hora_cadastro) VALUES ('$nome_plano', '$quemcadastrou', NOW())");
        $lastid = $conn->lastInsertId();

        foreach($_POST['informacao'] as $informacao){   
                $parcelaplano[''] = trim($_POST['parcelaplano']);
                $porcentagem[] = trim($_POST['porcentagem']);
                $conn->exec("INSERT INTO inform_plano (id_plano, parcelaplano, porcentagem) VALUES ('$lastid', '$parcelaplano', '$porcentagem')");
                print_r($informacao);
    }
    // commit the transaction
    $conn->commit();
     echo "<h1>CADASTRADO COM SUCESSO</h1>";
    }
catch(PDOException $e)
    {
    // roll back the transaction if something failed
    $conn->rollback();
    echo "Error: " . $e->getMessage();
    }

$conn = null;
    
asked by anonymous 27.01.2017 / 21:04

2 answers

2

Apparently the information you need to write is in the $informacao variable.

Try replacing the following lines:

$parcelaplano[''] = trim($_POST['parcelaplano']);
$porcentagem[] = trim($_POST['porcentagem']);

By:

$parcelaplano = trim($informacao['parcelaplano']);
$porcentagem = trim($informacao['porcentagem']);
    
27.01.2017 / 21:20
0

You are defining an array at this point in the code:

 $parcelaplano[''] = trim($_POST['parcelaplano']);
 $porcentagem[] = trim($_POST['porcentagem']);

Try to modify these two lines above, by these below:

 $parcelaplano = trim($_POST['parcelaplano']);
 $porcentagem = trim($_POST['porcentagem']);
    
27.01.2017 / 21:13