Page 1 of 1

Notice: Undefined index:

Posted: Sun Dec 15, 2002 12:51 pm
by k4tm4nn
I dont know if I posted this here before or not, but everybody that tried to help me on it, nothing seemed to work,,, Its driving me crazy

Im developing a script and i have a couple of Notice's:
----------------------------------------------------------------------
1.)
Notice: Undefined index: admin in index.php on line 34

2.)
Notice: Undefined index: featured in index.php on line 435
---------------------------------------------------------------------
I was told there is a way to get rid of these notice's in my code, without going into php.ini and hideing the notice's..

for the first notice (1)
----------------------------------------------------------------------
for a login, im using a cookie to keep the administrator logged in,,,

if ($_POST["user"] == $login && $_POST["password"] == $pass) {
setcookie("admin", "loggedin", "+3600");
header('Location: index.php');
}

it is called after the administrator logs in, then it will open the rest of the code..

if($_COOKIE['admin'] == "loggedin"){
(code here)
}

Now, i get the Notice before the user logs in on the login page,,, the login page is called be the else statement after the $cookie login...

else{
login page
}

so the variable is not = to anything at the time,,,

i was told to use issett() to fix that, but when i do, it dont work at all..

it just shows the login page over again,,
and dont login..

is there a way i can fix this?
----------------------------------------------------------------------

for the seconde notice (2):
----------------------------------------------------------------------
the seconde notice is just passing a variable with a check box,,, to another page...

here is the code i use for the check box:

if($_REQUEST["featured2"] == "yes") {
echo "<font color=red><B>Featured!<input name=featured type=hidden value=yes>";
}
else{
echo "Make Featured ? <input name=featured type=checkbox value=yes>";
}

the else statement is the part that shows up on page, and if the check box is not checked, then the value would be no, but i dont know how i can pass the variable featured=no to the next page with this check box,,, so on the next page i get the 2nd notice....

because im trying to call a variable that does equal anything,,,

ive even made an if statment on the next page to try to fix this,,, and it does work,,,

if($_REQUEST["featured"] == ""){
$_REQUEST["featured"] = "no";
}
ive even used;
if($_REQUEST["featured"] == 0){
$_REQUEST["featured"] = "no";
}
and it still gives me the same notice...

If there was a way to take the code from the check box like this:

<input name=featured type=hidden
<?
if($checked){
echo "value=yes>";
}
esle{
echo "value=no>";
}

would be so great,,,but we both no that wont work,, but its an example that i can only come up with...

any suggestions?

Posted: Sun Dec 15, 2002 7:42 pm
by hedge
anyplace where you check a value that could be empty add an isset

ie

instead of: if ($var==1) ...

if (isset($var) && $var==1) ...

It will short-circuit and php will skip the second test if $var is not set

Posted: Mon Dec 16, 2002 7:36 am
by Johnm
Find this line in the php.ini file:
error_reporting = E_ALL

Change it to this:
error_reporting = E_ALL & ~E_NOTICE

or to what ever you want but the ~E_NOTICE will keep notices from being displayed.


John M