<bodyng-app="deleteApp"ng-controller="deleteCtrl"><h1>MYSQL Delete with PHP in AngularJS</h1><tableborder="1"><tr><th>ID</th><th>Name</th><th>Mobile</th><th>Email</th><th>Delete</th></tr><trng-repeat="x in content" ><td>{{x.id}}</td><td>{{x.name}}</td><td>{{x.mobile}}</td><td>{{x. email}}</td><td><buttonng-click="delete(x.id)">Delete</button></td></tr></table><h3>Please Use Ctrl+F5 for Refresh</h3></body>
The “delete(x.id)” function is used to delete the specific data from the MySQL database.
The “deleteCtrl” used to create the controller for the Application with arguments $scope object and $http service.
The $http is a service and it is used to call the get method, this http get request will get the content from the “select.php” as response.
The response.data.details is used to get the response data.
The delete function is used to POST the arugument value to the “delete.php“.
The $scope.content=data is used to get the updated results as response data.
Sample code for delete.php:
<?phperror_reporting(0);$conn = new PDO("mysql:host=myServer;dbname=myDb", "myUser", "myPassword");$_POST = json_decode(file_get_contents('php://input'), true);if(!empty($_POST[value])){$del_query=$conn->prepare("delete from tbl_name where id=:id");$del_query->bindParam(':id, $_POST[value]);$chk_ins=$del_query->execute();}$sel_query = $conn->prepare("select * from tbl_name order by id ");$sel_query->execute();echo json_encode($sel_query->fetchAll());?>
Code Explanation for delete.php:
The $conn connection string used to connect the MySQL database by PHP.
The json_decode function is used to decode the JSON formatted POST data.
To check the posted data is empty or not.
To prepare the delete query for delete data from the MySQL Database table.
To bind the id value to the delete query.
To execute the delete query.
To select the updated data in the table.
To execute the select query.
To fetch all data from the result set and encode the data in JSON format.
Sample Output for MySQL Delete with PHP in AngularJS:
The output shows the form to get input from user. Then User click the delete button.
When user click the delete button then the data will be deleted from the MySQL database.
Related Searches to AngularJS delete using PHP Mysql
angularjs add edit delete exampleangularjs insert update delete using php mysqlinsert update delete using angularjsangularjs insert update delete exampleangularjs crud application demoangularjs insert update delete example in phpangularjs insert data to databasecrud operations using angularjs and javaangularjs crud gridangularjs php mysql crudangularjs with php tutorial pdfangularjs with php backendangularjs php frameworkangularjs php mysql exampleangularjs php mysql tutorialangularjs php mysql insertangularjs with mysql databaseinsert data using angularjs in phpinsert data using angularjs in mvcangularjs insert data to database phpangularjs save data to databaseangularjs with database example in javaangularjs database example