2
I have a php function that inserts two types of record in a Mysql table, according to the user’s choice in a combobox. The first combo option enters the records normally, but when I choose the second one it does not insert and does not show any error. In the Inspect element I see that all the form parameters are being passed correctly. Can someone help me ? Thank you
Follows the code:
if($funcao == 'email') {
$sql = "select * from mensageminterna where mensagem like '%<a h%';";
$rst = my_query($connR, $sql);
if($option == 'corretor'){
$sql = "insert into mensageminterna (codempresa, codusuarioremetente, codusuario, mensagem, icone, datacriacao)
select u.codempresa, u1.codusuario, u.codusuario, '$texto', 'cool', now() from usuario u
inner join usuario u1 on u.codempresa=u1.codempresa and u1.email like 'admin@%' and u1.indadministrador=1
where u.codsituacaousuario=1;";
$rst = my_execute($connW, $sql);
} elseif($option == 'gestor'){
$sql = "insert into mensageminterna (codempresa, codusuarioremetente, codusuario, mensagem, icone, datacriacao)
select u.codempresa, u1.nome remetente, u.nome destinatario, u.codtipousuario, '$texto', 'cool', now() from usuario u
inner join usuario u1 on u.codempresa=u1.codempresa and u1.email like 'admin@%' and u1.indadministrador=1
inner join tipousuario tu on tu.codtipousuario = u.codtipousuario
where u.codsituacaousuario=1 and tu.nome like '%geren%' or tu.nome like '%diret%' or tu.nome like '%coord%' or tu.nome like '%adm%' or tu.nome like '%super%';";
$rst = my_execute($connW, $sql);
} else {
echo "Não enviado";
}
exit;
}
<script language="JavaScript">
$(document).on('click', '#btnEnviar', function(event) {
event.preventDefault();
$("#funcao").val("email");
var self = $(this);
$.ajax({
url: "/email-broadcast.php",
type: "POST",
timeout:default_timeout,
data: $('#formemail').serialize(),
beforeSend: function(){
self.attr('disabled', 'true');
},
success: function() {
alert("Enviado com sucesso !");
},
error: function(jqXHR, textStatus){
console.log(textStatus, jqXHR);
},
complete: function(){
self.removeAttr('disabled');
}
});
});
</script>
<form method="post" name="formemail" action="/email-broadcast.php" id="formemail">
<input type="hidden" name="funcao" id="funcao" value="email"/>
<label style="margin-left: 7px">Destinatário:</label>
<select class="form-control" name="destinatario" id="destinatario" style="width: 250px;">
<option value="corretor" id="corretor" name="corretor">Corretores</option>
<option value="gestor" id="gestor" name="gestor">Gestores</option>
</select>
<textarea cols="86" rows="15" id="scriptenvio" name="scriptenvio" style=" margin-top: 10px;">
Blá blá blá
</textarea><br>
<button type="button" class="btn btn-default" id="btnEnviar" name="btnEnviar">Enviar</button>
</form>
I took the select of the second query (the one I wasn’t inserting) and it returned 464 records.
What API are you using to connect to the database? could you show where the attribution of
$option
?– rray
I use the mysqli...
– goldenleticia
And the assignment of
$option
where is?– rray
global $option;
$option = postget('destinatario');
stands before the start of the function– goldenleticia
See if the bank returned any error, with
mysql_error($conexao);
make an if on the call frommysqli_query()
ormysqli_execute()
– rray
So... the my_excecute function already handles the exceptions:
try {
$before = microtime(true);
if (! mysqli_query ( $conn, $query )) {
if (IS_DEV) {
echo "<hr>DB ERROR: " . mysqli_error ( $conn ) .
"<hr>";
}
addLog ( 'db.log', $query . '|'.$paginaatual.'|'.
mysqli_error ( $Conn ) );

throw new Exception(mysqli_error ( $Conn ));

#Exit();` }– goldenleticia
So there are no records that satisfy the select conditions. You can try to copy the query and test directly in the database with simulated values (the same sent in the form) and see if it returns something.
– rray
Let’s go continue this discussion in chat.
– goldenleticia
I don’t have access to xD chat
– rray
I’ll print it out in response
– goldenleticia
Remove that
exit;
of the code, it seems lost ...– rray
Your job
my_execute()
returns error when failed ? The message "unwrapped" has only effect if the variable$opcao
is not equal togestor
orcorretor
.– Edilson
No error returns, even I receive the message alert sent and all parameters are passed in the data form
– goldenleticia