PHP Notice: Trying to get property of non-object error

元气小坏坏 提交于 2019-12-12 03:26:17

问题


I'm using Factory in AngularJS, The Script is

app.factory('GetCountryService', function ($http, $q) {
        return {
            getCountry: function(str) {
                // the $http API is based on the deferred/promise APIs exposed by the $q service
                // so it returns a promise for us by default
                var url = "https://www.bbminfo.com/sample.php?token="+str;
                return $http.get(url)
                    .then(function(response) {
                        if (typeof response.data.records === 'object') {
                            return response.data.records;
                        } else {
                            // invalid response
                            return $q.reject(response.data.records);
                        }

                    }, function(response) {
                        // something went wrong
                        return $q.reject(response.data.records);
                    });
            }
        };

    });

My Output Response Screen Shot:

My PHP Script:

<?php



header("Access-Control-Allow-Origin: *");

header("Content-Type: application/json; charset=UTF-8");



session_start();


$ip = $_SERVER['REMOTE_ADDR'];

$dbname = "xyzData";
$link = mysql_connect("localhost", "Super", "Super") or die("Couldn't make connection.");
$db = mysql_select_db($dbname, $link) or die("Couldn't select database");

$uid = "";
$txt = 0;
$outp = "";

$data    = file_get_contents("php://input");
$objData = json_decode($data);

if (isset($objData->token))
    $uid = mysql_real_escape_string($objData[0]->token, $link);
else if(isset($_GET['uid']))
    $uid = mysql_real_escape_string($_GET['uid']);
else
    $txt += 1;

$outp ='{"records":[{"ID":"' . $objData->token . '"}]}';
echo($outp);

?>

I got error_log message is

[18-Mar-2016 21:40:40 America/Denver] PHP Notice: Trying to get property of non-object in /home/sample.php

I tried both $objData->token and $objData->token[0]. But I got the same error notice. Kindly assist me...

I tried the Solution provided in the Post Notice: Trying to get property of non-object error, But it fails so, I raised 50 Bounty Points for this post. I tried to update my requirement in that post Question https://stackoverflow.com/review/suggested-edits/11690848, But the Edit was Rejected so I posted my requirement as a new Question. Kindly assist me...


回答1:


The AngularJS is not sending any Object instead it passes the GET element.

Just access the Value by simply using $_GET['uid']




回答2:


$objData doesn't seem to be an object.

try $objData['token'].

Or echo the object $objData and try to figure out what is its structure.



来源:https://stackoverflow.com/questions/36097824/php-notice-trying-to-get-property-of-non-object-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!