[英]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.