I have textarea and three checkboxs in my mysql db by default textarea value as null and checkboxs values as zero(0).
when i enter some text in textarea i'm updating text value in my mysql db but i gotta stuck in checkbox things can some one suggest how to update checkbox checked value in mysql db
say for example if checkbox is checked/clicked i should be able to update my mysql db with value '1' if not the value will be '0'
db structure
ID TEXT ABC XYZ LMN
1 NULL 0 0 0
Thanks!
html
<div>
<textarea class="lb_text" rows="6" cols="50" placeholder="Add text here..."></textarea>
</div>
<div>
<label>
<input type='checkbox'>ABC
</label>
</div>
<div>
<label>
<input type='checkbox'>XYZ
</label>
</div>
<div>
<label>
<input type='checkbox'>LMN
</label>
</div>
<div>
<input type="submit" class="lb_save" value="submit">
</div>
php
if(isset($_POST['lb_text']))
{
$live_blog = mysqli_real_escape_string($_POST['lb_text']);
$sql = "update demo set text='".$live_blog."'";
$result = mysqli_query($con, $sql);
}
}
jquery
$(function(){
$(".lb_save").click(function(){
var lb_text = $('.lb_text').val();
if(lb_text == '')
{
alert("Enter Some Text...");
$('.lb_text').focus();
}
else
{
$.ajax({
type: "POST",
url: "index.php",
data:{
lb_text:lb_text,
},
success:function(response){
alert('successfully updated');
}
});
}
return false;
});
});
dataof$.ajax