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

Posted

技术标签:

【中文标题】无法使用 PHP MySQL 更新数据库,其中数据来自 AngularJS1.2 服务【英文标题】:Unable to update database with PHP MySQL where data is coming from AngularJS1.2 service 【发布时间】:2018-01-01 11:45:59 【问题描述】:

我是AngularJSphp mysql 的新手。

我正在尝试更新我的 PHP 数据库。

对于第一个表格,我插入了姓名、电子邮件、电话号码和密码的数据。之后,当我登录时,我想用国家、城市、州、密码和地址更新特定表。

但我得到了错误

更新 user_table SET(国家 = '印度',州 = '西孟加拉邦',城市 = '加尔各答',密码 = '700028',完整地址 = '4/6,Aswiny Dutta Road')WHERE email ='wri@ gmail.com'约会未更新Erreur de syntaxe pr�s de'(国家='印度',州='西孟加拉邦',城市='加尔各答',密码='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);


?>

提前谢谢你

【问题讨论】:

【参考方案1】:
$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 MySQL 更新数据库,其中数据来自 AngularJS1.2 服务的主要内容,如果未能解决你的问题,请参考以下文章

无法用php更新mysql数据库吗?

无法使用 php 和 Mysql 更新数据库

使用php从csv快速更新大量数据mysql [关闭]

无法保存 MySQL 查询 [重复]

AJAX 使用从 PHP 生成的 HTML 调用的函数更新 MYSQL 数据库

PHP/MYSQL:更新数据不起作用请看一下[重复]