简体   繁体   English

尝试修复“尝试在*行*上获取非对象的属性”错误

[英]Trying to fix a “Trying to get property of non-object in * on line *” error

Im aware this code might be vulnerable to SQL injection, it doesn't matter, this is a private home project that will never go public , the only person that can access this other than me is my dad and brother. 我知道此代码可能容易受到SQL注入的攻击,这没关系,这是一个永远不会公开的私人家庭项目,除我以外,唯一可以访问此代码的人是我的父亲和兄弟。

Im making a site where you press certain buttons, it sends you to a shop, but the shop doesn't load because of this error: 我在一个网站上按下了某些按钮,将您带到一家商店,但由于此错误,商店无法加载:

<b>Notice</b>:  Trying to get property of non-object in <b>shop.php</b> on line <b>12</b>

What could be wrong? 有什么事吗 I have tried looking for solutions on the internet but I found none. 我曾尝试在互联网上寻找解决方案,但没有找到解决方案。

This is the lines of code that this is affecting: 这是受影响的代码行:

if (!isset($HTTP_RAW_POST_DATA)) {
$HTTP_RAW_POST_DATA = file_get_contents("php://input");

$doc = new DOMDocument();
$doc->loadXML($HTTP_RAW_POST_DATA);

$intShopId = $doc->getElementsByTagName('intShopId');
$shop_id = $intShopId->item(0)->nodeValue;

The last line in this case is line 12. 在这种情况下的最后一行是第12行。

I know the reason of this is because $intShopId is not an object. 我知道这是因为$intShopId不是对象。 I think it needs to be a global variable passed as a parameter, but in this individual case I cant figure out whats wrong and i would appreciate some help. 我认为它必须是作为参数传递的全局变量,但在这种情况下,我无法弄清楚出了什么问题,我将不胜感激。

There might be some grammatical and/or spelling errors in the question here, I apologize if this is the case. 在此问题中可能存在语法和/或拼写错误,对于这种情况,我深表歉意。 I'm from Sweden. 我来自瑞典。

The problem is going to be with this line: 问题将出在这条线上:

$intShopId = $doc->getElementsByTagName('intShopId');

since there is no such tag as an <int> - or even any tag that even begins with that, then that method is returning null, or something else that isn't helpful. 由于没有这样的标记,例如<int> -甚至没有任何以该标记开头的标记,因此该方法返回null或其他无用的东西。

you are probably looking to use a method like : 您可能正在寻找使用类似的方法:

$doc->getElementById('intShopId');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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