PHP file error in ionic

Hi guys, I’m creating an ionic mobile application and I use php files to post data to my server. This is the error which is coming after I click the button.

And I checked the PHP file by copying the URL in the browser. It shows an error like this.
"
Notice: Trying to get property of non-object in /storage/h4/227/1095227/public_html/PHP Files/signUpQuery.php on line 44

Notice: Trying to get property of non-object in /storage/h4/227/1095227/public_html/PHP Files/signUpQuery.php on line 45

Notice: Trying to get property of non-object in /storage/h4/227/1095227/public_html/PHP Files/signUpQuery.php on line 46 "

Waiting for a quick response from you guys. Thank you! :slight_smile:

I will attach my signup.html file, controller code and php file here.
https://drive.google.com/open?id=0B1dxmRkJJRQDRVJjdlRqaEtDTU0

Go to the “Network” tab. See what the request to your PHP actually is and if and what response there is.

1 Like

Click on the file to get Request and Response details.

1 Like

image

image

Notice: Trying to get property of non-object in /storage/h4/227/1095227/publichtml/PHP Files/signUpQuery.php on line 44_

Notice: Trying to get property of non-object in /storage/h4/227/1095227/publichtml/PHP Files/signUpQuery.php on line 45_

Notice: Trying to get property of non-object in /storage/h4/227/1095227/publichtml/PHP Files/signUpQuery.php on line 46 "_

Base on these error logs and the php file you attached seems like your PHP $request did not received your data. Try dump your $request before assigning see what did your PHP received .

$request = json_decode($postdata);
var_dump($request);exit();
$fname = $request->fname;
$lname = $request->lname;
$email = $request->email;
1 Like

Added this in my php file. But the same error is showing

check your network, see what dose php return.

1 Like

You meant the network tab right?

Change your controller code to this, see if it works.

$http.post(link, {"fname":$scope.data.fname, "lname":$scope.data.lname, "email":$scope.data.email, "password":$scope.data.password}).then(function (res){
        $scope.response = res.data;
    });
1 Like

Same error friend!

And the second file that is requested? Is it requested at the same time?

From what I see in your first image in your first post your app is actually doing an OPTIONS request to figure CORS out. This means the Ionic app never actually DOES a POST because it thinks it is not allowed to.

Solution is here: https://enable-cors.org/server_php.html
(But please first confirm the second request)

@Codelives Slow down, one step after another :wink:

2 Likes

Yeah it is requested twice. That is why it shows two files.

Here! Now it’s only one file

And I have already put that code in my PHP file friend! :slight_smile:

Why is it now only one file that is being requested? What changed?

What we need to know is what kind of request is made for the file: POST or OPTIONS?
The OPTIONS request has to be answered with the correct headers so the POST request will be made.

1 Like

When I do an OPTIONS request to http://xpressrentals.000webhostapp.com/PHP%20Files/signUpQuery.php using Postman I don’t get any answer. (You can also use https://www.hurl.it/ to test this online)

1 Like

Previously I clicked that signup button twice. That’s why it showed as two requests :stuck_out_tongue:

Yeah something wrong :frowning:

Some webhosts don’t support OPTIONS requests.

2 Likes

:frowning: :frowning:

But when I copy and paste the URL of that PHP in my browser Data is getting inserted as blank data.

See

That means they are allowing us to post data right?

Yes. The host support GET and POST. But your app needs OPTIONS for security reasons. Read about “CORS” if you want to know the background.

1 Like