简体   繁体   English

选中复选框时,如何使用 php 更新 mysql 数据库中的值?

[英]How can i update a value in mysql database with php when a checkbox is checked?

In database i am updating the height of an image and after the checkbox is checked i want to see the image with that height.Any idea what should i be using to achieve this?在数据库中,我正在更新图像的高度,在选中复选框后,我想查看具有该高度的图像。知道我应该使用什么来实现这一点吗? An example would be appreciated.一个例子将不胜感激。

Okay, what you need to do is implement ajax for async call to database for updating image's height in database and vanilla JavaScript (or jQuery) to resize image after the request is successful.好的,您需要做的是实现 ajax 以异步调用数据库以更新数据库中图像的高度,并实现香草 JavaScript(或 jQuery)以在请求成功后调整图像大小。

For Example:例如:

HTML HTML

<input type="checkbox" name="your_checkbox" value="50" onclick="changeHeight(this);">

<img src="image/url/here.jpg" alt="foo" class="your-class" id="img">

JavaScript JavaScript

let changeHeight = checkbox => {
    if(checkbox.checked){
        $.ajax({
            url: 'your/path/to/updating/file.php',
            type: 'POST',
            data: {img_height: checkbox.value}
            success: res => {
                $('#img').css({height: checkbox.value+'px'});
            },
            error: err => {
                console.error(err);
            }
        });
    }
}

PHP PHP

$height = $_POST['img_height'];

// query to update height in the database...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 mysql 布尔值加载复选框选中状态,并在选中复选框时动态更改数据库中的 mysql 布尔值? - How can I load a checkbox checked status from a mysql bool, and change the mysql bool in the database dynamically when the checkbox is checked? 在我的表{AJAX}中选中复选框后如何使数据库更新值 - How do I make my database update a value when a checkbox is checked in my table { AJAX } 当我单击php中的保存amt按钮时如何更新复选框选中的行 - How can i update checkbox checked rows when i click on save amt button in php PHP更新数据库(如果未选中此复选框) - Php update database if checkbox is not checked 当复选框选中时,mysql将枚举从no更新为数据库中的复选框值 - mysql update enum from no to checkbox value in database when check box checked 使用循环选中复选框时,如何显示值? - How can i show value when checkbox was checked using loop for? 如何根据数据库中的值使复选框处于选中状态或不选中状态 - How can I make a checkbox checked or not checked depending on what the value is in the database php复选框被选中,然后mysql更新1,如果没有选中mysql更新0 - Php checkbox is checked, then mysql update 1, and if not checked mysql update 0 在mysql查询数组中的复选框值时检查php格式? - Php form checked when the checkbox value in array mysql query? 如何在 MySql 数据库中将复选框值存储为是 - PHP - How do I store a checkbox value as yes in MySql Database - PHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM