I have a php function that inserts two record types into a Mysql table, according to the user's choice in a combobox. The first option of the combo inserts the records normally, but when I choose the second one it does not insert and it does not acknowledge any error. In the inspect element I see that all the parameters of the form are being passed correctly. Can someone help me ? Thank you
Follow 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 got the select from the second query (which I was not inserting) and it returned me 464 records.