gpt4 book ai didi

php - 无法使用 PHP MySQL 更新数据库,其中数据来自 AngularJS1.2 服务

转载 作者:行者123 更新时间:2023-11-29 18:35:43 25 4
gpt4 key购买 nike

我是 AngularJSPHP 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 de syntaxe pr�s de '(country = 'India', state = 'West Bengal', city = 'Kolkata', pincode = '700028',' � la ligne 1

下面是我的代码。

Controller :

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);
}

?>

提前谢谢

最佳答案

$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."'";

关于php - 无法使用 PHP MySQL 更新数据库,其中数据来自 AngularJS1.2 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45322108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com