/    Sign up×
Community /Pin to ProfileBookmark

undefined index???

Can someone please explain to me what undefined index means???

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@hastxJul 30.2007 — I usually see them when initializing a variable but there is no value to be passed (ie $x=$_GET['x']; ...but x was never passed), and are usually presented as notices. if you turn off notices you wont see them.
Copy linkTweet thisAlerts:
@NogDogJul 30.2007 — I usually see them when initializing a variable but there is no value to be passed (ie $x=$_GET['x']; ...but x was never passed), and are usually presented as notices. if you turn off notices you wont see them.[/QUOTE]

Don't turn off notices; fix your code, instead. For instance, if your code does...

[code=php]
$x = $_GET['x'];
[/code]
...instead, do...
[code=php]
$x = '';
if(isset($_GET['x']))
{
$x = $_GET['x'];
}
[/code]

Alternatively, you can use a more compact syntax using the ternary ("? :") operator:
[code=php]
$x = (isset($_GET['x'])) ? $_GET['x'] : '';
[/code]

Notices are generated for a reason. All of them can be avoided with properly written code.
Copy linkTweet thisAlerts:
@hastxJul 31.2007 — Don't turn off notices; fix your code, instead. For instance, if your code does...

Notices are generated for a reason. All of them can be avoided with properly written code.[/QUOTE]


I would agree with fixing the code, but it is still a good practice to turn off all error reporting on a production machine.
Copy linkTweet thisAlerts:
@NogDogJul 31.2007 — I would agree with fixing the code, but it is still a good practice to turn off all error reporting on a production machine.[/QUOTE]
Yes, turn off [b]display_errors[/b] for the production system, but you can still leave error_reporting at a high level. Just log the errors to an error log file via the log_errors and error_log configuration settings, instead. (Or, get creative with set_error_handler() and write them to a database. ? )
Copy linkTweet thisAlerts:
@hastxJul 31.2007 — my bad, yes display_errors.
Copy linkTweet thisAlerts:
@novemberGreyauthorJul 31.2007 — awesome! thankyou guys for your help...
×

Success!

Help @novemberGrey spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...