-2
Friends, I am doing an AJAX with PHP but the record is going empty. What I am doing wrong?
function newColor() {
var nome = document.getElementById("descricao_cor").value;
var cor = document.getElementById("hexadecimal").value;
alert (nome);
alert(cor);
$.ajax({
url: "atualiza-cor.php",
type: "GET",
data: { descricao_cor: "nome", hexadecimal: "cor" },
cache: false,
success: function() {
document.adm.submit();
$('#btnSelecionar').trigger('click');
}
});
}
The Alerts work well. And there’s PHP like this:
//NOVA COR
if (isset($_GET['novaCor']) && ($_GET['novaCor']) != '') {
echo $sql_novacor = 'INSERT INTO veiculos0_cores (descricao_cor,relevancia,hexadecimal) VALUES("' . $_POST['nome'] . '","", "' . $_POST['cor'] . '")';
mysql_query($sql_novacor) or die(mysql_error());
}
And a record is entered, but it’s empty. I’m not finding the problem. Someone help me, please?
[]s
In PHP you are checking if $_GET['novaCor'] is set, but you are not sending. No Insert vc is putting in value $_POST['name'] and $_POST['color'] but the method you are going through is GET.
– André Vicente