A simple angular 1.x $https.post which submits a name ("J Doe") and a phone number (1234567):
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"> </script>
<script>
var app = angular.module('myApp',[]);
app.controller('myCtrl',function($scope,$http){
$scope.insertData=function(){
$http.post("cgi-bin/in.cgi",{
'bname':$scope.bname,
'bphone':$scope.bphone
}).then(function(response){
console.log("Data Inserted Successfully");
},function(error){
alert("Sorry! Data Couldn't be inserted!");
console.error(error);
});
}
});
</script>
</head>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<form>
Name:- <input type="text" ng-model="bname" />
Phone:-<input type="text" ng-model="bphone" />
<input type="button" value="Submit" ng-click="insertData()" />
</form>
</div>
</body>
</html>
To a Perl script which does an insert into MySQL:
#!/usr/bin/perl -w
use strict;
use warnings;
use CGI qw(:standard);
use DBI;
use POSIX qw(strftime);
use JSON;
my $sql;
my $dbh = DBI->connect('****', '****', '****') || die "Connecting from Perl to MySQL database failed: $DBI::errstr";
my $cgi = CGI->new;
my $name = $cgi->param('bname') || "unknown";
my $phone = $cgi->param('bphone') || "unknown";
print "Content-type:text/html\r\n\r\n";
$sql = "insert into TestDB values ('$name', '$phone')";
$dbh->do("$sql") || die ("Connecting from Perl to MySQL database failed: $DBI::errstr");
$dbh->disconnect;
print "Record insert successfully";
But the only thing being inserted into the DB is:
+---------+---------+
| Name | Phone |
+---------+---------+
| unknown | unknown |
+---------+---------+
1 row in set (0.00 sec)
The name and phone are nowhere, but a print of $cgi->param('POSTDATA') give the following:
{"json":"J Doe"}
OK, I found the name, "J Doe", along with some weird "json" key, but where's the phone number?
What am I missing?