Jump to content
MakeWebGames

Error on every page almost


boionfire81

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
}
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 2 weeks later...

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 1 month later...
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" ;)

Link to comment
Share on other sites

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...

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...