boionfire81 Posted March 14, 2016 Posted March 14, 2016 A different version of the same error on every page about. ***** Replaces the change in each page A non-critical error has occurred. Page execution will continue. Below are the details: PHP Notice: Undefined index: ****** (8) Line executed: /home/public_html/88.php:** The basic of it all Undefined (8) what do I do? Quote
G7470 Posted March 14, 2016 Posted March 14, 2016 From my past experience, this usually means that you are attempting to evaluate a variable that currently is not defined yet. The way I normally fix it is wherever that variable is being evaluated (usually in an if statement), turn that if statement into something like this: if (isset($variable) && <other condition that evaluates $variable>) { isset() in PHP manual: http://php.net/manual/en/function.isset.php ~G7470 Quote
boionfire81 Posted March 14, 2016 Author Posted March 14, 2016 here is one line $ret.="\n<option value='{$r['itmid']}'"; Quote
boionfire81 Posted March 14, 2016 Author Posted March 14, 2016 Im a hobby coder. So what I do know is basically self taught through reading actual code, trial & error, interacting with other coders on real code. That page above seriously isnt part of my language. lol I tried but, it just is 100% over my head. Quote
KyleMassacre Posted March 19, 2016 Posted March 19, 2016 PHP doesn't really like when arrays are used without checking if it exists or is set. For example your $r['itmid'], it is actually set through your database but PHP is too dumb to realize that. There are ways to fix it for example, the easy not recommended way is to turn of your error reporting or just have it print to a file. Another is to explicitly assign/set it: //assign or set it to itself or you can assign it to a local variable $r['itmid'] = isset($r['itmid']) ? $r['itmid'] : null; //or you can check to see if it exists if(array_key_exists(['itmid','someThingElse'],$r)) { //continue on } Quote
boionfire81 Posted March 19, 2016 Author Posted March 19, 2016 ok so just [color=#000000][color=#007700]if([/color][color=#0000BB]array_key_exists[/color][color=#007700]([[/color][color=#DD0000]'itmid'[/color][color=#007700],[/color][color=#DD0000]'someThingElse'[/color][color=#007700]],[/color][color=#0000BB]$r[/color][color=#007700])) {[/color][/color] then let the file flow through & add an extra } at the end? Quote
KyleMassacre Posted March 19, 2016 Posted March 19, 2016 Pretty much Just remember, you can't use it all he time because the 2 functions check for different things. isset() will check to make sure that there is a value for the most part and array_key_exists() checks to see if there is a key in the array. Quote
SRB Posted March 21, 2016 Posted March 21, 2016 the easy not recommended way is to turn of your error reporting Say what now? I get the impression all these errors are on a production server, so I'd definitely advice to turn error reporting off. To be fair, undefined variables are a warning, not an error, so it's safe to just suppress them or turn error reporting off. Depends on how anal you are about it though - I personally run error reporting at highest level because I don't like even the warnings. 1 Quote
KyleMassacre Posted March 21, 2016 Posted March 21, 2016 Say what now? I get the impression all these errors are on a production server, so I'd definitely advice to turn error reporting off. To be fair, undefined variables are a warning, not an error, so it's safe to just suppress them or turn error reporting off. Depends on how anal you are about it though - I personally run error reporting at highest level because I don't like even the warnings. Oops don't even know why I said that just thinking backwards. If your on a production machine then yeah turn reporting off. But if your still in dev mode I wouldn't know why people through it up on a live server anyways Quote
Magictallguy Posted March 28, 2016 Posted March 28, 2016 Oops don't even know why I said that just thinking backwards. If your on a production machine then yeah turn reporting off. But if your still in dev mode I wouldn't know why people through it up on a live server anyways bcoz ppl dun no cde lyk we do That, and newbies are exactly that. The amount of times I had buggy code on production servers was insane and beyond idiotic. Suppressed all errors to all but myself though, so that was easy enough Quote
boionfire81 Posted March 29, 2016 Author Posted March 29, 2016 dunno what you mean poduction/dev. It's visible via http://www.com but considering no one knows the url. I'm old skool here. From back in the days of cgi. Shoot I still hand write code. Quote
KyleMassacre Posted March 29, 2016 Posted March 29, 2016 A production environment generally means it's open to the public. A development environment generally means it's done locally. Just because no one knows your URL doesn't mean they can't get to it. If people do get to it then they could exploit your system and retrieve your database information Quote
boionfire81 Posted April 6, 2016 Author Posted April 6, 2016 Guys :( I don't know why I just can't grasp the undefined. >.< But in Bounty v2 (paid mod) Undefined index: bounty the line code is echo "<a href='attack.php?nextstep=$ns&ID={$_GET['ID']}&wepid={$r['itmid']}&bounty={$_GET['bounty']}'>{$r['itmname']}</a><br />"; so the &bounty={$_GET['bounty']} may or may not exist -.- what to do? Quote
KyleMassacre Posted April 6, 2016 Posted April 6, 2016 You must check that the array key exists or that it is set. Put a couple of my words together and you have your functions that you need. But here, I will write it for you. Just a FYI this will be my last time giving you an answer without you providing what you providing what you have attempted to rectify the warning: $bounty = isset($_GET['bounty']) && array_key_exists('bounty',$_GET) ? (abs((int)$_GET['bounty']) + 0 : NULL; Now, $bounty will return one of 3 things here. I could make it return one of 3 things but that's really spoon feeding you ;). It will return either 0 (which also equals false), a number greater than 0, or null. Some things to look at possibly are some ctype functions, filter_var/filter_input, preg_match, or even preg_replace and not to mention the 3 other functions I listed in the code which are pretty self explanatory Quote
Magictallguy Posted May 15, 2016 Posted May 15, 2016 Recommending use of ctype_digit() over abs(intval($var)) + 0 for this instance.. $bounty = array_key_exists('bounty', $_GET) && ctype_digit($_GET['bounty']) ? $_GET['bounty'] : null; 1 Quote
KyleMassacre Posted May 15, 2016 Posted May 15, 2016 Recommending use of ctype_digit() over abs(intval($var)) + 0 for this instance.. $bounty = array_key_exists('bounty', $_GET) && ctype_digit($_GET['bounty']) ? $_GET['bounty'] : null; Well lets talk about somethings here, granted, yours may be better for this instance because it is using $_GET and chances are that will be a string and hasnt been type casted to an Int. But what the OP needs to understand is that with ctype_digit it has to be a string otherwise it will be false for many inputs due to the fact of the ASCII table. With my example it will convert it over to at minimum a string value of 0 then convert it to an Int type otherwise its null. "string" + 0 = "0" ;) Quote
Magictallguy Posted May 16, 2016 Posted May 16, 2016 Granted, but in this case, you're expecting an int/float, not a string ;) Quote
sniko Posted May 16, 2016 Posted May 16, 2016 Well lets talk about somethings here, granted, yours may be better for this instance because it is using $_GET and chances are that will be a string and hasnt been type casted to an Int. But what the OP needs to understand is that with ctype_digit it has to be a string otherwise it will be false for many inputs due to the fact of the ASCII table. With my example it will convert it over to at minimum a string value of 0 then convert it to an Int type otherwise its null. "string" + 0 = "0" ;) Also, you're "modifying" user input (by +0) and not just validating it. But yeah, both work. I'd choose ctype_digit() for this instance also, but eh... 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.