gpt4 book ai didi

javascript - 使用ajax和php更新数据库

转载 作者:行者123 更新时间:2023-12-03 02:34:17 25 4
gpt4 key购买 nike

我试图在选中该复选框时将我的数据库tinyint更新为1,在取消选中该复选框时将其更新为0。我的 Javascript/Ajax 代码是:

<script>
function emailNextWithAddress(chk,address) {
var nextEmail, inside_where;
if(chk.checked === true){
$.ajax({
url: "marca_enviado.php",
type: "get",
data: address,
success: function(){
nextEmail = document.createElement('input');
nextEmail.id = address;
nextEmail.value = address;
nextEmail.type = 'text';
nextEmail.name = 'email[]';
nextEmail.className = 'insemail';
nextEmail.style.display = 'inline-block';
inside_where = document.getElementById('addEmail');
inside_where.appendChild(nextEmail);
},
error: function(){
console.log("Erro!");
}
});
} else {
$.ajax({
url: "desmarca_enviado.php",
type: "get",
data: address,
success: function(){
inside_where = document.getElementById(address);
inside_where.parentNode.removeChild(inside_where);
},
error: function(){
console.log("Erro!");
}
});
}
return false;
}
</script>

尝试更新我的数据库tinyint的php(marca_enviado.php)代码是:

<?php
include_once 'dbh.php';

$address = $_GET['address'];

$updateEnviado = "UPDATE escolas SET Enviado = 1 WHERE id= 'address' ";

$result = mysqli_query($conn , $updateEnviado);
?>

最佳答案

<?php
include_once 'dbh.php';

$address = $_GET['address'];

//-- escape the input data. But be sure to add some validations before this line.
$address = mysqli_real_escape_string($conn, $address);

//-- use "$address" variable there, assuming that variable contains the id
$updateEnviado = "UPDATE escolas SET Enviado = 1 WHERE id= '$address' ";

$result = mysqli_query($conn , $updateEnviado);
?>

希望对你有帮助!

关于javascript - 使用ajax和php更新数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48600076/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com