Instantly share code, notes, and snippets.

View form.php
<!doctype html>
<html>
<head>
<title>AngularJS, PHP, MySQL</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
<script src="js/app.js"></script>
View crud.php
<?php
include 'config.php';
$data = json_decode(file_get_contents("php://input"));
$request_type = $data->request_type;
// Get all records
if($request_type == 1){
View config.php
<?php
$host = ""; /* Host name */
$user = ""; /* User */
$password = ""; /* Password */
$dbname = ""; /* Database name */
$con = mysqli_connect($host, $user, $password,$dbname);
// Check connection
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
View app.js
var fetch = angular.module('myapp', []);
fetch.controller('userCtrl', ['$scope', '$http', function ($scope, $http) {
// Get all records
$http({
method: 'post',
url: 'CRUD.php',
data: {request_type:1},
View users.sql
CREATE TABLE `users` (
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`username` varchar(80) NOT NULL,
`fname` varchar(80) NOT NULL,
`lname` varchar(80) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
View phptest.php
<?php
# Fill our vars
$dbname = '';
$dbuser = '';
$dbpass = '';
$dbhost = '';
$connect = mysqli_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");