<?php
$server="localhost";
$user="root";
$pass="iq123";
$db="test";
$conn= mysqli_connect($server,$user,$pass,$db);
if (!$conn){
echo "mysqli_error().'Database not connected'";
}
?>
<?php
include("conn.php");
$data=json_decode(file_get_contents("php://input"));
$name=$data->name;
$price=$data->price;
$quantity=$data->quantity;
$sql="Insert into product(name,price,quantity)values('$name','$price','$quantity')";
$query=mysqli_query($conn,$sql);
?>
<!DOCTYPE>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>InsertData</title>
<script src="js/angular.js" language="javascript" type="text/javascript"></script>
<script src="js/angular.min.js" language="javascript" type="text/javascript"></script>
<link href="css/bootstrap.css" rel="stylesheet" type="text/css"/>
</head>
<body ng-app='myapp' ng-controller="productController">
<h2>CRUD with AngularJS</h2>
<table class='table table-hover'>
<tr>
<th>Id </th>
<th>Name </th>
<th>Price </th>
<th>Quantity </th>
<th>option </th>
</tr>
<tr ng-repeat="product in listproduct">
<td>{{product.id}}</td>
<td>{{product.name}}</td>
<td>{{product.price}}</td>
<td>{{product.quantity}}</td>
<td>
<a class='btn btn-danger' href="#" ng-click="del(product.id)">Delete</a> |
<a class='btn btn-info' href="#" ng-click="selectEdit(product.id)">Edit</a>
</td>
</tr>
</table>
<h3>product Information </h3>
<table class='table table-bordered'>
<tr>
<td>Id</td>
<td><input type='text' class='form-control' ng-model='id'></td>
</tr>
<tr>
<td>Name</td>
<td><input type="text" class='form-control' ng-model="name"></td>
</tr>
<tr>
<td>Price</td>
<td><input type="text" class='form-control' ng-model='price'></td>
</tr>
<tr>
<td>Quantity</td>
<td><input type='text' class='form-control' ng-model='quantity'></td>
</tr>
<tr>
<td> </td>
<td>
<input type='button' class='btn btn-primary' value="Add" ng-click="add()">
<input type='button' class='btn btn-info' value="Save" ng-click="edit()">
<input type='button' class='btn btn-success' value="Insert" ng-click="insert()">
</td>
</tr>
</table>
<script>
var myapp = angular.module('myapp', []);
myapp.controller('productController',function($scope,$http){
$scope.listproduct = [
{id: 'p01',name:'Mobile',price:10000, quantity:20},
{id: 'p02',name:'Fridge',price:50000, quantity:20},
{id: 'p03',name:'TV',price:45000, quantity:20},
{id: 'p04',name:'Desktop',price:12500, quantity:20},
{id: 'p05',name:'Air Contion',price:75000, quantity:20},
];
$scope.add = function(){
$scope.listproduct.push({
id:$scope.id, name:$scope.name, price:$scope.price, quantity:$scope.quantity
});
$scope.id = '';
$scope.name = '';
$scope.price = '';
$scope.quantity = '';
};
$scope.insert = function(){
$http.post("insertData.php",
{'name':$scope.name,
'price':$scope.price,
'quantity':$scope.quantity
})
.success(function(data,status,headers,config){
alert("Data Isnserted Successfully");
//window.location.href = 'viewPage.php';
})
};
$scope.edit = function(){
var index = getSelectIndex($scope.id);
$scope.listproduct[index].name = $scope.name;
$scope.listproduct[index].price = $scope.price;
$scope.listproduct[index].quantity = $scope.quantity;
};
$scope.selectEdit = function(id){
var index = getSelectIndex(id);
var product = $scope.listproduct[index];
$scope.id = product.id;
$scope.name = product.name;
$scope.price = product.price;
$scope.quantity = product.quantity;
};
$scope.del = function(id){
var result = confirm('Are you sure?');
var index = getSelectIndex(id);
$scope.listproduct.splice(index, 1);
};
function getSelectIndex(id){
for(var i=0;i<$scope.listproduct.length; i++)
if($scope.listproduct[i].id==id)
return i;
return -1;
}
});
</script>
</body>
</html>
$server="localhost";
$user="root";
$pass="iq123";
$db="test";
$conn= mysqli_connect($server,$user,$pass,$db);
if (!$conn){
echo "mysqli_error().'Database not connected'";
}
?>
<?php
include("conn.php");
$data=json_decode(file_get_contents("php://input"));
$name=$data->name;
$price=$data->price;
$quantity=$data->quantity;
$sql="Insert into product(name,price,quantity)values('$name','$price','$quantity')";
$query=mysqli_query($conn,$sql);
?>
<!DOCTYPE>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>InsertData</title>
<script src="js/angular.js" language="javascript" type="text/javascript"></script>
<script src="js/angular.min.js" language="javascript" type="text/javascript"></script>
<link href="css/bootstrap.css" rel="stylesheet" type="text/css"/>
</head>
<body ng-app='myapp' ng-controller="productController">
<h2>CRUD with AngularJS</h2>
<table class='table table-hover'>
<tr>
<th>Id </th>
<th>Name </th>
<th>Price </th>
<th>Quantity </th>
<th>option </th>
</tr>
<tr ng-repeat="product in listproduct">
<td>{{product.id}}</td>
<td>{{product.name}}</td>
<td>{{product.price}}</td>
<td>{{product.quantity}}</td>
<td>
<a class='btn btn-danger' href="#" ng-click="del(product.id)">Delete</a> |
<a class='btn btn-info' href="#" ng-click="selectEdit(product.id)">Edit</a>
</td>
</tr>
</table>
<h3>product Information </h3>
<table class='table table-bordered'>
<tr>
<td>Id</td>
<td><input type='text' class='form-control' ng-model='id'></td>
</tr>
<tr>
<td>Name</td>
<td><input type="text" class='form-control' ng-model="name"></td>
</tr>
<tr>
<td>Price</td>
<td><input type="text" class='form-control' ng-model='price'></td>
</tr>
<tr>
<td>Quantity</td>
<td><input type='text' class='form-control' ng-model='quantity'></td>
</tr>
<tr>
<td> </td>
<td>
<input type='button' class='btn btn-primary' value="Add" ng-click="add()">
<input type='button' class='btn btn-info' value="Save" ng-click="edit()">
<input type='button' class='btn btn-success' value="Insert" ng-click="insert()">
</td>
</tr>
</table>
<script>
var myapp = angular.module('myapp', []);
myapp.controller('productController',function($scope,$http){
$scope.listproduct = [
{id: 'p01',name:'Mobile',price:10000, quantity:20},
{id: 'p02',name:'Fridge',price:50000, quantity:20},
{id: 'p03',name:'TV',price:45000, quantity:20},
{id: 'p04',name:'Desktop',price:12500, quantity:20},
{id: 'p05',name:'Air Contion',price:75000, quantity:20},
];
$scope.add = function(){
$scope.listproduct.push({
id:$scope.id, name:$scope.name, price:$scope.price, quantity:$scope.quantity
});
$scope.id = '';
$scope.name = '';
$scope.price = '';
$scope.quantity = '';
};
$scope.insert = function(){
$http.post("insertData.php",
{'name':$scope.name,
'price':$scope.price,
'quantity':$scope.quantity
})
.success(function(data,status,headers,config){
alert("Data Isnserted Successfully");
//window.location.href = 'viewPage.php';
})
};
$scope.edit = function(){
var index = getSelectIndex($scope.id);
$scope.listproduct[index].name = $scope.name;
$scope.listproduct[index].price = $scope.price;
$scope.listproduct[index].quantity = $scope.quantity;
};
$scope.selectEdit = function(id){
var index = getSelectIndex(id);
var product = $scope.listproduct[index];
$scope.id = product.id;
$scope.name = product.name;
$scope.price = product.price;
$scope.quantity = product.quantity;
};
$scope.del = function(id){
var result = confirm('Are you sure?');
var index = getSelectIndex(id);
$scope.listproduct.splice(index, 1);
};
function getSelectIndex(id){
for(var i=0;i<$scope.listproduct.length; i++)
if($scope.listproduct[i].id==id)
return i;
return -1;
}
});
</script>
</body>
</html>
Comments
Post a Comment