Atualizar tabela ao mudar select
Pessoal, tenho o seguinte codigo:
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","getFaixa.php?q="+str,true);
xmlhttp.send();
}
}
Na mesma página, logo embaixo:
<select name='faixa' id='appearance-select' onchange="showUser(this.value)">
<option value='branca' <?=($faixa == 'branca')?'selected':''?>>Branca</option>
<option value='azul' <?=($faixa == 'azul')?'selected':''?>>Azul</option>
<option value='roxa' <?=($faixa == 'roxa')?'selected':''?>>Roxa</option>
<option value='marrom' <?=($faixa == 'marrom')?'selected':''?>>Marrom</option>
<option value='preta' <?=($faixa == 'preta')?'selected':''?>>Preta</option>
</select><br>
No getFaixa.php:
include("conexao.php");
$q = intval($_GET['q']);
$id = $_SESSION['id'];
$update = "UPDATE usuario SET faixa='$q' WHERE usuario_id='$id'";
$result = mysqli_query($conexao, $update);
O que eu gostaria era mudar o campo no BD, usando ajax.
Ele até está mudando, só que está botando um 0 ao invés do value do select.
Alguém poderia me ajudar?
Onde estou errando?
Grato.Discussão (2)
Carregando comentários...