I am having an issue were when i click edit the data only shows up on the same page not sure how to get it to redirect and show up on another page.
controller partial code just the edit and update function
/** function to edit product details from list of product referencing php **/
$scope.prod_edit = function(index) {
$scope.update_prod = true;
$scope.add_prod = false;
$http.post('db.php?action=edit_product',
{
'prod_index' : index
}
)
.success(function (data, status, headers, config) {
//alert(data[0]["prod_name"]);
$scope.prod_id = data[0]["id"];
$scope.prod_name = data[0]["prod_name"];
$scope.prod_desc = data[0]["prod_desc"];
$scope.prod_price = data[0]["prod_price"];
$scope.prod_quantity = data[0]["prod_quantity"];
})
.error(function(data, status, headers, config){
});
}
/** function to update product details after edit from list of products referencing php **/
$scope.update_product = function() {
$http.post('db.php?action=update_product',
{
'id' : $scope.prod_id,
'prod_name' : $scope.prod_name,
'prod_desc' : $scope.prod_desc,
'prod_price' : $scope.prod_price,
'prod_quantity' : $scope.prod_quantity
}
)
.success(function (data, status, headers, config) {
$scope.get_product();
alert("Product has been Updated Successfully");
})
.error(function(data, status, headers, config){
});
}
});
db.php
/** Function to Edit Product **/
function edit_product() {
$data = json_decode(file_get_contents("php://input"));
$index = $data->prod_index;
$qry = mysql_query('SELECT * from product WHERE id='.$index);
$data = array();
while($rows = mysql_fetch_array($qry))
{
$data[] = array(
"id" => $rows['id'],
"prod_name" => $rows['prod_name'],
"prod_desc" => $rows['prod_desc'],
"prod_price" => $rows['prod_price'],
"prod_quantity" => $rows['prod_quantity']
);
}
print_r(json_encode($data));
return json_encode($data);
}
/** Function to Update Product **/
function update_product() {
$data = json_decode(file_get_contents("php://input"));
$id = $data->id;
$prod_name = $data->prod_name;
$prod_desc = $data->prod_desc;
$prod_price = $data->prod_price;
$prod_quantity = $data->prod_quantity;
// print_r($data);
$qry = "UPDATE product set prod_name='".$prod_name."' , prod_desc='".$prod_desc."',prod_price='.$prod_price.',prod_quantity='.$prod_quantity.' WHERE id=".$id;
$qry_res = mysql_query($qry);
if ($qry_res) {
$arr = array('msg' => "Product Updated Successfully!!!", 'error' => '');
$jsn = json_encode($arr);
// print_r($jsn);
} else {
$arr = array('msg' => "", 'error' => 'Error In Updating record');
$jsn = json_encode($arr);
// print_r($jsn);
}
}
?>
The page i need it to redirect is http://localhost/angular_php/create_update.php
<!DOCTYPE html>
<html ng-app="listpp" ng-app lang="en">
<head>
<meta charset="utf-8">
<link href="assets/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
ul>li, a{cursor: pointer;}
</style>
<title>Angular With PHP</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js">
</script>
<script src="controller.js"></script>
</head>
<body>
<?php include "templates/header.php";?>
<br><br>
<div ng-controller="maincontroller">
<div class="wrapper">
<div class="container col-sm-8 col-sm-offset-2">
<div class="page-header">
<h4>Add/Update Product</h4>
</div>
<form class="form-horizontal" name="add_product" >
<input type="hidden" name="prod_id" ng-model="prod_id">
<div class="form-group">
<label for="firstname" class="col-sm-2 control-label">Prod Name</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="prod_name" ng-model="prod_name"
placeholder="Enter Product Name">
</div>
</div>
<div class="form-group">
<label for="lastname" class="col-sm-2 control-label">Prod Desc</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="prod_desc" ng-model="prod_desc"
placeholder="Enter Product Description">
</div>
</div>
<div class="form-group">
<label for="lastname" class="col-sm-2 control-label">Prod Price</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="prod_price" ng-model="prod_price"
placeholder="Enter Product Price">
</div>
</div>
<div class="form-group">
<label for="lastname" class="col-sm-2 control-label">Prod Quantity</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="prod_quantity" ng-model="prod_quantity"
placeholder="Enter Product Quantity">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default" name="submit_product" ng-show='add_prod' value="Submit" ng-click="product_submit()">Submit</button>
<button type="submit" class="btn btn-default" name="update_product" ng-show='update_prod' value="Update" ng-click="update_product()">Update</button>
</div>
</div>
</div>
</form>
</div>
</div>
<script src="assets/js/ui-bootstrap-tpls-0.10.0.min.js"></script>
</body>
</html>