AngularJs http post Request To PHP json

Today, We want to share with you AngularJs http post Request To PHP json.In this post we will show you how to send data from angularjs to php, hear for AngularJs Simple Example: Post Data to PHP page we will give you demo and example for implement.In this post, we will learn about how to call php function from angularjs controller with an example.

AngularJs http post Request To PHP json

There are the Following The simple About AngularJs http post Request To PHP json Full Information With Example and source code.

As I will cover this Post with live Working example to develop Posting Form Data With $http In AngularJS, so the How to Submit Form with Validation in AngularJS with PHP for this example is following below.

Read Also:  how to add two numbers in javascript?

Step 1: HTML Part


<!DOCTYPE html>
<html ng-app>
        <title>AngularJs Post Example: </title>
        <script type="text/javascript" src=""></script>
                border:1px solid #DBDCE9; margin-left:auto;
                border-radius:7px;padding: 25px;

                border: 1px solid;margin: 11px 0px;
                padding:11px;color: #00529B;
                background-color: #BDE5F8;list-style: none;
                border: 1px solid;  margin: 11px 0px;
                padding:11px;  color: #D8000C;
                background-color: #FFBABA;   list-style: none;
        <div id='dv1'>
            <form ng-controller="productController">
                    <li class="err" ng-repeat="error in display_err"> {{ error}} </li>
                    <li class="info" ng-repeat="r_message in r_messages"> {{ r_message}} </li>
                <h2>Product Submit Form</h2>
                    <label>Product Name</label> 
                    <input type="text" ng-model="livename" placeholder="Product Name" style='margin-left: 22px;'> 
                    <label>Shop Key</label>
                    <input type="text" ng-model="liveshop_key" placeholder="Shop Key" style='margin-left: 22px;'> 
                    <label>product auth Token</label>
                    <input type="password" ng-model="product_auth" placeholder="product_auth">
                <button ng-click='productSubmit();' style='margin-left: 63px;margin-top:10px'>productSubmit</button>

        <script type="text/javascript">
            function productController($scope, $http) {
                $scope.display_err = [];
                $scope.r_messages = [];

                $scope.productSubmit = function() {

                    $scope.display_err.splice(0, $scope.display_err.length); // delete all error messages
                    $scope.r_messages.splice(0, $scope.r_messages.length);

                    $'post_es.php', {'pname': $scope.livename, 'product_auth': $scope.product_auth, 'shop_key': $scope.liveshop_key}
                    ).success(function(data, status, headers, config) {
                        if (data.r_message != '')
                    }).error(function(data, status) { 
        <a href=''></a>

Step 2: PHP Code

simple PHP source Code will be:


$data = json_decode(file_get_contents("php://input"));
$product_name = mysql_real_escape_string($data->pname);
$product_auth = mysql_real_escape_string($data->product_auth);
$shop_key = mysql_real_escape_string($data->shop_key);

$con = mysql_connect('localhost', 'root', '');
mysql_select_db('pakainfo', $con);

$qry_em = 'select count(*) as cnt from products where shop_key ="' . $shop_key . '"';
$qry_res = mysql_query($qry_em);
$res = mysql_fetch_assoc($qry_res);

if ($res['cnt'] == 0) {
    $qry = 'INSERT INTO products (name,pass,shop_key) values ("' . $product_name . '","' . $product_auth . '","' . $shop_key . '")';
    $qry_res = mysql_query($qry);
    if ($qry_res) {
        $my_res_array = my_res_arrayay('r_message' => "Product Created Successfully!!!", 'error' => '');
        $results_json = json_encode($my_res_array);
    } else {
        $my_res_array = my_res_arrayay('r_message' => "", 'error' => 'Error In inserting record');
        $results_json = json_encode($my_res_array);
} else {
    $my_res_array = my_res_arrayay('r_message' => "", 'error' => 'Product Already exists with same shop_key');
    $results_json = json_encode($my_res_array);

Web Programming Tutorials Example with Demo

Read :

Read Also:  Custom Service using Angular Example


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about AngularJs http post Request To PHP json.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  AngularJS HTTP AJAX Example Tutorial From Scratch
  2. Read Also:  Top 10 Common PHP Job Interview Questions and Answers
  3. Read Also:  C# Linq Left Outer Join using LINQ To SQL Tutorial
  4. Read Also:  jquery Drag and Drop draggable droppable Example
  5. Read Also:  Http Post Method using Angular Example
  6. Read Also:  Server side Laravel DataTables example
  7. Read Also:  Angular Grid Alternate row color Example
  8. Read Also:  Angular 9/8 Get Checked Radio Button on Change Event
  9. Read Also:  how to create One to Many Relationship in laravel?
  10. Read Also:  Http JSONP Service using Angular Example