php - Update checkbox and textarea value in mysql db using Jquery -


i have textarea , 3 checkboxs in mysql db default textarea value null , checkboxs values zero(0).

when enter text in textarea i'm updating text value in mysql db gotta stuck in checkbox things can 1 suggest how update checkbox checked value in mysql db

say example if checkbox checked/clicked should able update mysql db value '1' if not value '0'

https://jsfiddle.net/07wmpjqf/1/

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 text...");             $('.lb_text').focus();         }         else         {             $.ajax({                 type: "post",                 url: "index.php",                 data:{                     lb_text:lb_text,                  },                 success:function(response){                     alert('successfully updated');                 }             });         }         return false;     }); }); 

add id check box , capture th value in jquery.

<div>     <label>         <input type='checkbox' id="abc">abc     </label> </div> <div>     <label>         <input type='checkbox' id="xyz">xyz     </label> </div> <div>     <label>         <input type='checkbox' id="lmn">lmn     </label> </div> 

and change ajax data this,

data: {     lb_text: lb_text,     abc: $("#abc").is(':checked') ? 1 : 0,     xyz: $("#xyz").is(':checked') ? 1 : 0,     lmn: $("#lmn").is(':checked') ? 1 : 0, }, 

and query this,

$live_blog = mysqli_real_escape_string($_post['lb_text']); $abc = $_post['abc'] $xyz = $_post['xyz'] $lmn = $_post['lmn'] $sql = "update demo set text='".$live_blog."',abc='".$abc."',xyz='".$xyz."',lmn='".$lmn."'"; 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -