0
I have the following code:
echo "<select id='posto[]' name='posto[]' multiple='multiple'>";
foreach ($postos as $lista) {
echo '<option value=' . $lista->getCodigoPosto() . '>' . $lista->getNomePosto() . '</option>';
}
echo "</td>";
echo "</select>";
Inside a form with method GET, when the user does Submit I take the codes he selected in OPTION and put in a variable as if it were a list:
$postosSelecionados = $_REQUEST['posto'];
So I move this list into a recording method:
if (isset($_REQUEST['posto'])) {
if (UsuarioCadastradoDAO::aprovar($codigo, $aprovador, $postosSelecionados) == FALSE) {
echo "alert('Ocorreu algum erro ao aprovar, favor tentar novamente.');</script>";
}
}
See the method:
public static function aprovar($codUsuarioAprovado, $codUsuarioAprovador, $listaDePostos) {
try {
$banco = new Banco();
$banco->setComandoSQL("INSERT INTO `UsuarioMasterAprovado` (`IdUsuario`, `IdUsuarioAprovador`, `DataAprovacao`) VALUES (:UsuarioCadastrado,:UsuarioAprovador, CURDATE()); UPDATE `Usuario` SET `Aprovado` = 1 WHERE IdUsuario = :UsuarioCadastrado");
$parametros = array(
':UsuarioCadastrado' => $codUsuarioAprovado,
':UsuarioAprovador' => $codUsuarioAprovador,
);
$banco->ExecutaSQLPreparada($parametros);
foreach ($listaDePostos as $lista) {
$banco->setComandoSQL("INSERT INTO `Usuario_Posto`(`Posto_idPosto`, `UsuarioMasterAprovado_IdUsuario`) VALUES (:idPostos,LAST_INSERT_ID()");
$parametros = array(
':idPostos' => $lista
);
$banco->ExecutaSQLPreparada($parametros);
}
return TRUE;
} catch (Exception $ex) {
return FALSE;
}
}
However something is wrong and I am not able to identify the error, because it is not recording in the database.
Is there an error? auto commit turned on? check if
ExecutaSQLPreparada()
returns some error.– rray
The.o does not do
return false;
no catch at least shows the Exception, so you know at least where to start.– rray