VueJS CRUD Operations with PHP and MySQLi Example
In this Post We Will Explain About is VueJS CRUD Operations with PHP and MySQLi Example With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to vue Select Insert Update Delete In Php MySQL Example
In this post we will show you Best way to implement Vue.js Update and Delete Data using PHP, hear for VueJS insert, view, edit, delete and update using PHP and Mysql with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.
Vue.js CRUD Operation with PHP/MySQLi
In this Example,First of all Add or Include External Libs Like as a(jQuery, css etc..), and then create a simple index.php or index.html page.After that crate a simple javascript file like as a index.js or main.js, It is also add your web-application First Header Part to some priority set.After that Include your relevant CSS Class.
modal.php
Edit User
Remove UserYou want to Remove User
{{userClick.userfname}} {{userClick.userlname}}
style.css
.headerEdit{ height:45px; font-size:20px; padding-left:18px; padding:8px; background: #4CAF50; color: #c60000; } .modelheaderdel{ height:45px; font-size:20px; padding-left:18px; padding:8px; background: #3d3d3d; color: #c60000; } .editCloseBtn{ background: #4CAF50; color: #c60000; border:none; } .removeCloseBtn{ background: #3d3d3d; color: #c60000; border:none; }
Updating our index.php
Vue.js Insert, update and delete Operation using PHP/MySQLi css/bootstrap.min.css"Vue.js Insert Update Delete Operation with PHP/MySQLi
User List
{{ msgError }}{{ msgsuccess }}
User Firstname User Lastname Action {{ user.userfname }} {{ user.userlname }}
Adding Update and Remove Code in our API
api.php
if($crudopration == 'update'){ $userid = $_POST['userid']; $userfname = $_POST['userfname']; $userlname = $_POST['userlname']; $sql = "update users set userfname='$userfname', userlname='$userlname' where userid='$userid'"; $query = $conn->query($sql); if($query){ $out['msg'] = "User Updated Successfully"; } else{ $out['error'] = true; $out['msg'] = "Could not update User"; } } if($crudopration == 'delete'){ $userid = $_POST['userid']; $sql = "delete from users where userid='$userid'"; $query = $conn->query($sql); if($query){ $out['msg'] = "User Deleted Successfully"; } else{ $out['error'] = true; $out['msg'] = "Could not delete User"; } }
Updating our Vue Code
main.js
var main = new Vue({ el: '#users', data:{ usershowaddmdl: false, usershowEditmdl: false, showDeleteModal: false, msgError: "", msgsuccess: "", users: [], newUser: {userfname: '', userlname: ''}, userClick: {} }, mounted: function(){ this.getAllUsers(); }, methods:{ getAllUsers: function(){ axios.get('api.php') .then(function(results){ //console.log(results); if(results.data.error){ main.msgError = results.data.msg; } else{ main.users = results.data.users; } }); }, saveUser: function(){ //console.log(main.newUser); var usrForm = main.myFormData(main.newUser); axios.post('api.php?crudopration=create', usrForm) .then(function(results){ //console.log(results); main.newUser = {userfname: '', userlname:''}; if(results.data.error){ main.msgError = results.data.msg; } else{ main.msgsuccess = results.data.msg main.getAllUsers(); } }); }, updateUser(){ var usrForm = main.myFormData(main.userClick); axios.post('api.php?crudopration=update', usrForm) .then(function(results){ //console.log(results); main.userClick = {}; if(results.data.error){ main.msgError = results.data.msg; } else{ main.msgsuccess = results.data.msg main.getAllUsers(); } }); }, removeUser(){ var usrForm = main.myFormData(main.userClick); axios.post('api.php?crudopration=delete', usrForm) .then(function(results){ //console.log(results); main.userClick = {}; if(results.data.error){ main.msgError = results.data.msg; } else{ main.msgsuccess = results.data.msg main.getAllUsers(); } }); }, selectUser(user){ main.userClick = user; }, myFormData: function(obj){ var dataForm = new FormData(); for(var key in obj){ dataForm.append(key, obj[key]); } return dataForm; }, clsMsg: function(){ main.msgError = ''; main.msgsuccess = ''; } } });
VueJS INSERT, UPDATE and DELETE
You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example
I hope you have Got What is vue Select Insert Update Delete In Php MySQL And how it works.I would Like to have FeedBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.