0
I wanted to save the two data (from sector and from sector) but he is saving only the first in the two
Insertion script (html):
<div class="form-group">
<label for="de_setor" class="w3-text-black">Do setor de:</label>
<select class="form-control" required id="de_setor" name="de_setor">
<option value=""disabled selected hidden>Selecione...</option>
<?php
while($linha = $pegadiv->fetch(PDO::FETCH_ASSOC)){
?>
<option name="<?= $linha['setor_id'] ?>"> <?= $linha['setor'] ?> </option>
<?php
}
?>
</select>
<label for="para_setor" class="w3-text-black">Para o setor de:</label>
<select class="form-control" required id="para_setor" name="para_setor">
<option value=""disabled selected hidden>Selecione...</option>
<?php
while($linha2 = $pegadiv2->fetch(PDO::FETCH_ASSOC)){
?>
<option name="<?= $linha2['setor_id'] ?>"> <?= $linha2['setor'] ?> </option>
<?php
}
?>
</select>
</div>
Insertion script (php):
$acao = (isset($_POST['acao'])) ? $_POST['acao'] : '';
$numero = $_POST['numero'];
$assunto = $_POST['assunto'];
$requerente = $_POST['requerente'];
$status = $_POST['status'];
$de_setor = (isset($_POST['de_setor']));
$para_setor = (isset($_POST['para_setor']));
$informe = $_POST['informe'];
$data = $_POST['data'];
$informante = (isset($_POST['informante']));
$processo_id = (isset($_POST['processo_id']));
if ($acao == 'incluir'){
$processos = "INSERT INTO processos(numero, assunto, requerente, status)VALUES(:numero, :assunto, :requerente, :status)";
$stm = $conexao->prepare($processos);
$stm->bindValue(':numero', $numero);
$stm->bindValue(':assunto', $assunto);
$stm->bindValue(':requerente', $requerente);
$stm->bindValue(':status', $status);
if($stm->execute()){
$lastid = $conexao->lastInsertId();
$informes = "INSERT INTO informes(de_setor, para_setor, informe, data, informante, processo_id)VALUES (:de_setor, :para_setor, :informe, :data, :informante, :processo_id)";
$tsm = $conexao->prepare($informes);
$tsm->bindValue(':de_setor', $de_setor);
$tsm->bindValue(':para_setor', $para_setor);
$tsm->bindValue(':informe', $informe);
$tsm->bindValue(':data', $data);
$tsm->bindValue(':informante', $informante);
$tsm->bindValue(':processo_id', $lastid);
if ($tsm->execute()){
BD:
How are you saving the form? How do you recover the values of the fields in the Formulars? Try returning the "$para_sector". See if it’s coming right from the form
– Danielle Arruda torres
Ué? to saving with the insert script in php. all_processo.php. is in Pdo
– Bernardo Rodel
$para_setor = (isset($_POST['para_setor'])); is returning right?
– Danielle Arruda torres
I believe so, after all the problem is not in the insertion process but in the select that pulls the </option> from the database. <label for="de_sector" class="W3-text-black">Sector of:</label> <select class="form-control" required id="de_sector" name="de_sector"> <option value=""disabled Selected Hidden>Select...</option> <? php while($line = $pegadiv->fetchAll(PDO::FETCH_ASSOC)){ ? > <option value="<?= $line['setor_id'] ? >""<?= $line['sector'] ? >"></option> <? php } ? > </select>
– Bernardo Rodel
the problem is here :<option value="<?= $line['setor_id'] ? >""<?= $line['sector'] ? >"> this way he will only see the setor_id , because the other is outside the scope
– Danielle Arruda torres
or you concatenate or you create another attribute that receives it
– Danielle Arruda torres
how I would concatenate that line?
– Bernardo Rodel
if you can help me, I’d appreciate it! thanks in advance.
– Bernardo Rodel