简体   繁体   中英

Unable to update database with PHP MySQL where data is coming from AngularJS1.2 service

I am new in AngularJS and as well as in PHP MySQL .

I am trying to update my PHP database.

For the first form I have inserted data for name, email, phone number and password. After that when I login I want to update the specific table with country, city, state, pincode and address.

But I am getting the error

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

Here is my code below.

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

service:

 '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 code:

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

?>

Thank you in advance

$abc = "UPDATE user_table SET (country = '".$country."', state = '".$state."', city = '".$city."', pincode = '".$pincode."', fulladdress = '".$address."') WHERE email ='".$email."'";

The bracket should not be here, due to which the problem was occurring. The correct code should be

$abc = "UPDATE user_table SET country = '".$country."', state = '".$state."', city = '".$city."', pincode = '".$pincode."', fulladdress = '".$address."' WHERE email ='".$emailid."'";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM