php angular使用,如何使用angular.js PHP从mysql显示数据?
您好,您可以查看以下示例代碼
你的HTML頁面:
AngularJs Post Example: DevZone.co.in#dv1{
border:1px solid #DBDCE9; margin-left:auto;
margin-right:auto;width:220px;
border-radius:7px;padding: 25px;
}
.info{
border: 1px solid;margin: 10px 0px;
padding:10px;color: #00529B;
background-color: #BDE5F8;list-style: none;
}
.err{
border: 1px solid; margin: 10px 0px;
padding:10px; color: #D8000C;
background-color: #FFBABA; list-style: none;
}
- {{ error}}
- {{ msg}}
Sigup Form
Name
Password
SignUp
function FrmController($scope,$http) {
$scope.errors = [];
$scope.msgs = [];
$scope.SignUp = function() {
$scope.errors.splice(0,$scope.errors.length); // remove all error messages
$scope.msgs.splice(0,$scope.msgs.length);
$http.post('post_es.PHP',{'uname': $scope.username,'pswd': $scope.userpassword,'email': $scope.useremail}
).success(function(data,status,headers,config) {
if (data.msg != '')
{
$scope.msgs.push(data.msg);
}
else
{
$scope.errors.push(data.error);
}
}).error(function(data,status) { // called asynchronously if an error occurs
// or server returns response with an error status.
$scope.errors.push(status);
});
}
}
Devzone.co.in
Your PHP code
$data = json_decode(file_get_contents("PHP://input"));
$usrname = MysqL_real_escape_string($data->uname);
$upswd = MysqL_real_escape_string($data->pswd);
$uemail = MysqL_real_escape_string($data->email);
$con = MysqL_connect('localhost','root','');
MysqL_select_db('test',$con);
$qry_em = 'select count(*) as cnt from users where email ="' . $uemail . '"';
$qry_res = MysqL_query($qry_em);
$res = MysqL_fetch_assoc($qry_res);
if ($res['cnt'] == 0) {
$qry = 'INSERT INTO users (name,pass,email) values ("' . $usrname . '","' . $upswd . '","' . $uemail . '")';
$qry_res = MysqL_query($qry);
if ($qry_res) {
$arr = array('msg' => "User Created Successfully!!!",'error' => '');
$jsn = json_encode($arr);
print_r($jsn);
} else {
$arr = array('msg' => "",'error' => 'Error In inserting record');
$jsn = json_encode($arr);
print_r($jsn);
}
} else {
$arr = array('msg' => "",'error' => 'User Already exists with same email');
$jsn = json_encode($arr);
print_r($jsn);
}
?>
請檢查上面的代碼,您將了解它將如何工作.如果您遇到任何問題,請在評論欄中告訴我
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的php angular使用,如何使用angular.js PHP从mysql显示数据?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 连接驱动_在jdbc中完成对于jdbc参
- 下一篇: 镜头视场角计算工具_再谈远心镜头的设计及