Question:
php undefined index help?
DUDE
2011-06-05 17:39:55 UTC
My php is strict and I'm getting an undefined index on line 104.
Line 104 is part of an if statement.

if (!in_array(strtoupper($_GET['p']), $alphabet)) {
$_GET['p'] = 'a';
}

How can i fix this?
Three answers:
Robin T
2011-06-08 22:10:43 UTC
Change your if statement to this:



if (!array_key_exists('p', $_GET) || !in_array(strtoupper($_GET['p']), $alphabet)) {
SurferTim850
2011-06-05 18:19:17 UTC
$_GET[] is used to collect values passed by a form method="get". The php code probably does not like this:



$_GET['p'] = 'a';
?
2016-11-19 00:39:36 UTC
it incredibly is stable practice once you assign very own abode page variables to make effective they have a cost, so as that in the event that they don't have a cost you could direct human beings back to the foremost website with a particular errors message or verify if a cost has been further. use the isset command, like this: if (isset($_POST['txtP']){ $w=$_POST['txtP']; echo $w; } else { echo "you would be able to desire to fill out the variety."; //could be any errors message. }


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...