3
I need to update a table in the database, reading the data entered in the input, by clicking the button. This is what I have so far:
HTML:
<td>ADSL</td>
<td class="superdanger"> <input type="number" id="vmadsl" placeholder="<?php echo "Valor atual: (Acima de ".$placeholder[0]."%)"; ?>"></input> </td>
<td class="superwarning"> <input type="number" id="aadsl" placeholder="<?php echo "Valor atual: (Acima de ".$placeholder[1]."%)"; ?>"></input> </td>
<td class="success"> <input type="number" id="vdadsl" placeholder="<?php echo "Valor atual: (Acima de ".$placeholder[2]."%)"; ?>"></input> </td>
<td> <button type="submit" id="teste"/</button> </td>
AJAX SCRIPT:
<script>
$(function(){
$('#teste').click(function(){
$.ajax({
type : 'post',
url : 'capacidade/relatorios/ricardo/matriz_capacidadericardo/attbutttonadsl.php',
data : {vermelho: $('#vmadsl').val(), amarelo: $('#aadsl').val()},
success: function (response) {
alert('Alterado com sucesso');
},
error: function () {
alert('Erro');
}
});
});
});
</script>
PHP:
<?php
include 'capacidade/background_bd_conexao.php';
$vermelhoadsl = $_POST["vermelho"];
$amareloadsl = $_POST["amarelo"];
mysql_query(" UPDATE valor FROM matriz_coloracao WHERE nome = 'Vermelho ADSL' SET valor = '".$vermelhoadsl."' ");
mysql_query(" UPDATE valor FROM matriz_coloracao WHERE nome = 'Amarelo ADSL' SET valor = '".$amarelogadsl."' ");
?>
Not that it has anything to do with the problem but it has an error in HTML: it must be
<button type="submit" id="teste">BLABLAH</button>
– Miguel
What mistake are you making?
– Michelle Akemi
can be sending the form, try to cancel the event by clicking #test button
– wwwjsw
He is not changing anything in the bank, the error seems to me to be that he does not take the values of "red" and "yellow". Thanks @Miguel
– Guilherme Campos
The warning "Successfully altered" is printed.
– Guilherme Campos