我是AngularJS
以及PHP
MySQL
的新用户。
我正在尝试更新我的PHP
数据库。
对于第一个表格,我已插入姓名,电子邮件,电话号码和密码的数据。在我登录之后,我想用国家,城市,州,密码和地址更新特定的表格。
但我收到了错误
UPDATE user_table SET(country ='India',state ='West Bengal',city ='Kolkata',pincode ='700028',fulladdress ='4/6,Aswiny Dutta Road')WHERE email ='wri @ gmail.com'appointment NOT UpdatedErreur desyntaxepr sde'(country ='India',state ='West Bengal',city ='Kolkata',pincode ='700028',' la ligne 1
以下是我的代码。
控制器:
angular.module('cartApp.userprofile.controller', []).controller('UserprofileController', ['$scope','loginFactory','signupFactory',function($scope,loginFactory,signupFactory){
$scope.userListAry = [];
$scope.userListFn = function(){
loginFactory.fetchSingleDatatoServerFn()
.then(function(singleUser){
console.log('singleUser',singleUser)
$scope.userListAry = singleUser.data;
console.log('user profile controller data: '+JSON.stringify($scope.userListAry));
},function(){
console.log('data cannot retrieved');
})
}
$scope.userListFn();
$scope.submitAddress = function(country,city,state,pincode,address){
console.log('country: '+country+' city: '+city+' state: '+state+' pincode: '+pincode+' address: '+address)
var useremail = $scope.userListAry.email;
signupFactory.loginAddressFn(country,city,state,pincode,address,useremail);
} }]);
服务:
'use strict';
angular.module('cartApp.signup.services', []).factory('signupFactory',['$http','$q',function($http,$q){
var signupObj = {
setSignupFormFn : setSignupFormFn,
getSignupFormFn : getSignupFormFn,
signupArray : [],
fetchDatatoServerFn : fetchDatatoServerFn,
loginAddressFn : loginAddressFn
};
function setSignupFormFn(username,userphno,useremail,userpass,userconfirmpass){
var signupValueObj = {};
signupValueObj.username = username;
signupValueObj.userphno = userphno;
signupValueObj.useremail = useremail;
signupValueObj.userpass = userpass;
signupValueObj.userconfirmpass = userconfirmpass;
signupObj.signupArray.push(signupValueObj);
$http({
url : 'data/form.php',
method : 'POST',
data: {
'username': username,
'userphno': userphno,
'useremail': useremail,
'userpass': userpass,
'userconfirmpass': userconfirmpass,
},
}).success(function(data, status, headers, config){
alert(username);
signupObj.fetchDatatoServerFn();
}).error(function(){
alert('no insert')
});
}
function getSignupFormFn(){
return signupObj.signupArray;
}
function fetchDatatoServerFn(){
var defer = $q.defer();
$http({
url : 'data/fetchformdata.php',
method : 'GET',
}).success(function(data){
signupObj.fetchFormData = data;
defer.resolve(data);
}).error(function(){
defer.reject('data can\'t be retained');
});
return defer.promise;
}
function loginAddressFn(country,city,state,pincode,address,useremail){
var defer = $q.defer();
$http({
url : 'data/updateform.php',
method : 'PUT',
data :{
'useremail' : useremail,
'country' : country,
'city' : city,
'state' : state,
'pincode' : pincode,
'address' : address
}
}).success(function(data){
defer.resolve(data);
console.log('data: '+data);
}).error(function(){
defer.reject('data can\'t be retrieved');
});
return defer.promise;
}
return signupObj;
}]);
PHP代码:
<?php
$connect = mysqli_connect('localhost','root','','signup_form');
$data = json_decode( file_get_contents('php://input') );
$email = mysqli_real_escape_string($connect, $data->useremail);
$country = mysqli_real_escape_string($connect, $data->country);
$state = mysqli_real_escape_string($connect, $data->state);
$city = mysqli_real_escape_string($connect, $data->city);
$pincode = mysqli_real_escape_string($connect, $data->pincode);
$address = mysqli_real_escape_string($connect, $data->address);
$abc = "UPDATE user_table SET (country = '".$country."', state = '".$state."', city = '".$city."', pincode = '".$pincode."', fulladdress = '".$address."') WHERE email ='".$email."'";
mysqli_query($connect, $abc);
if(mysqli_affected_rows($connect) > 0){
echo "<span style='display: block; padding: 10px 15px; color: #2E6A00; border: 2px solid #2E6A00;'>Appointment Updated</span>";
}else{
echo "<span style='display: block; padding: 10px 15px; color: #D32F00; border: 2px solid #D32F00;'>Appointment NOT Updated</span>";
echo mysqli_error($connect);
}
?>
提前谢谢
答案 0 :(得分:0)
$abc = "UPDATE user_table SET (country = '".$country."', state = '".$state."', city = '".$city."', pincode = '".$pincode."', fulladdress = '".$address."') WHERE email ='".$email."'";
支架不应该在这里,因为问题正在发生。正确的代码应该是
$abc = "UPDATE user_table SET country = '".$country."', state = '".$state."', city = '".$city."', pincode = '".$pincode."', fulladdress = '".$address."' WHERE email ='".$emailid."'";