Javascript 使用ajax和php更新数据库

Javascript 使用ajax和php更新数据库,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我正在尝试在选中复选框时将我的数据库tinyint更新为1,在取消选中复选框时将其更新为0。我的Javascript/Ajax代码是: <script> function emailNextWithAddress(chk,address) { var nextEmail, inside_where; if(chk.checked === true){ $.ajax({ url: "marca_enviado.php",

我正在尝试在选中复选框时将我的数据库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);
 ?>

希望有帮助

运行此代码时出现了什么错误?@LakmalAbesekara没有错误,只是没有更新数据库。$updateEnviado=update escolas SET Enviado=1,其中id='address'这里有多处错误,您总是更新到1,并且总是更新id为'address'的记录,而这可能不会exist@Herco我有一个php文件要更新为1,还有一个php文件要更新为0。id='address'不是来自Ajax数据:address吗?在数据:address中,address是什么?
<?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);
 ?>