Bootstrap Toggle switch with ajax update to mysql in PHP

Bootstrap Toggle switch with ajax update to mysql in PHP

Today, We want to share with you Bootstrap Toggle switch with ajax update to mysql in PHP.
In this post we will show you Bootstrap Toggle switch with ajax update to mysql in PHP, hear for Bootstraps Toggle switch with ajax update to mysql in PHP we will give you demo and example for implement.
In this post, we will learn about Bootstraps Toggle switch with ajax update to mysql in PHP with an example.

Bootstrap Toggle is a very highly flexible and interactive Bootstrap plugin that converts simple checkboxes into toggles class.

Example of Bootstrap Toggle using mysql and PHP

store value from on/off button in mysql database using php ajax in This Post.

First of all you should include this js Lib.Like as a jQuery,bootstrap-toggle js and css and bootstrap js.

Include jquery

Simple header part include This libs.


index.html

This is a dynemic body part of table enabled or disabled using Bootstrap Toggle

Page ID Page Name Page Title Page Keywods Page Desc Action Status

script.js

This is a main part of the logic call ajax and update with php to mysql send id and mode like mode as a true or false


do_switch.php

simple here mode is true when button is enabled and mode is false when button is disabled.

 $message='Hey my button is enableed!!';
$success='Enabled';
echo json_encode(array('message'=>$message,'$success'=>$success));
}

else if ($mode=='false')
{
$str=$db->query("update pages SET status=0 where pid=$pid");
$message='Hey my button is disable!!';
$success='Disabled';
echo json_encode(array('message'=>$message,'success'=>$success));

}
?>

View Demo

Leave a Comment