Page 1 of 1
big problem, lots of undefined indexes help
Posted: Sat Dec 02, 2006 3:04 pm
by Mythic Fr0st
I have lots of undefined indexes, ( Notices ) but they're all over my screen
I cant get them off
Question 1: will they be seen, when I actually upload the website to a server?
Question 2: how do I get rid of them
I dont know how cus
I have 2 pages...
"Signup" and "mailpage"
when you click signup it checks if the text boxes have enough or not to much text in them
(username, password, confirm password)
it also checks if password matches confirm password & e-mail matches confirm e-mail
but the way I check is if (strlen($_POST['nameofbox'], but I get the notice, because 'nameofbox' doesnt exist on this page, but it exists on another page, and must be checked
how do I fix this?
Posted: Sat Dec 02, 2006 3:06 pm
by Burrito
have a look at
isset()
to answer your 2 questions:
1) it depends on the host...more than likely they have error reporting off so people would not see the warnings...but that does NOT mean you shouldn't address them
2) check to see if the variable
isset() before using its output.
Posted: Sat Dec 02, 2006 3:06 pm
by feyd
isset() and/or
array_key_exists() may be of interest.
ty
Posted: Sat Dec 02, 2006 4:02 pm
by Mythic Fr0st
Thanks, but how would I use it,

Posted: Sat Dec 02, 2006 4:04 pm
by Zoxive
hmm
Posted: Sat Dec 02, 2006 4:24 pm
by Mythic Fr0st
Burrito | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Didnt do anything
Code: Select all
if(isset($_POST['user']))
{
print $_POST['user'];
}
this is the error...
Notice: Undefined index: user in c:\program files\easyphp1-8\www\test\youhavebeene-mailed.php on line 25
putting that isset() thing infront of it didnt make it go away
( I have 12 others of these )
there not actually variables incase you didnt realize, there names of textboxes / radio buttons / check boxes / password boxes
Burrito | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Sat Dec 02, 2006 4:32 pm
by Burrito
is there perhaps another instance of $_POST['user']?
what you have, by all accounts, should work.
hmm
Posted: Sat Dec 02, 2006 4:46 pm
by Mythic Fr0st
it works fine, BUT I HATE THIS NOTICES, they're evil, they make the page look funny, this is the entire code OK?
Code: Select all
<html>
<head>
<style type="text/css">
body
{
background-image:
url('SilverBG.jpg')
}
</style>
</head>
<img src="Mythic Aeons Banner.jpg" width="1008" height="125">
<div align='center'>
<body>
<?php
$bool[3]=true;
$bool[4]=true;
$bool[5]=true;
$bool[6]=true;
$bool[7]=true;
$bool[8]=true;
if (strlen($_POST['user']) < 5)
{
$bool[3]=false;
echo '<font color="blue" size="4">Error:</font><font color="blue" size="3"><i> Your username must be no less then 5 characters long.<br/></i></font>';
}
else if (strlen($_POST['user']) > 18)
{
$bool[6]=false;
echo '<font color="blue" size="4">Error:</font><font color="blue" size="3"><i> Your username must be no more then 18 characters long.<br/></i></font>';
}
else
{
echo '<b>Your username is the correct length.</b><br/>';
}
if (strlen($_POST['pw1']) < 5)
{
$bool[4]=false;
echo '<font color="blue" size="4">Error:</font><font color="blue" size="3"><i> Your password must be no less then 5 characters long.<br/></i></font>';
}
else if (strlen($_POST['pw1']) > 20)
{
$bool[7]=false;
echo '<font color="blue" size="4">Error:</font><font color="blue" size="3"><i> Your password must be no more then 20 characters long.<br/></i></font>';
}
else
{
echo '<b>Your password is the correct length.</b><br/>';
}
if (strlen($_POST['pw2']) < 5)
{
$bool[5]=false;
echo '<font color="blue" size="4">Error:</font><font color="blue" size="3"><i> Your confirm password must be no less then 5 characters long.<br/></i></font>';
}
else if (strlen($_POST['pw2']) > 20)
{
$bool[8]=false;
echo '<font color="blue" size="4">Error:</font><font color="blue" size="3"><i> Your confirm password must be no more then 20 characters long.<br/></i></font>';
}
else
{
echo '<b>Your confirm password is the correct length.</b><br/>';
}
if (strlen($_POST['user']) > 18)
{
$bool[6]=false;
echo 'bool 6';
}
if (strlen($_POST['pw1']) > 20)
{
$bool[7]=false;
echo 'bool 7';
}
if (strlen($_POST['pw2']) > 20)
{
$bool[8]=false;
echo 'bool 8';
}
$email[1]=$_POST['email1'];
$email[2]=$_POST['email2'];
$pw[1]=$_POST['pw1'];
$pw[2]=$_POST['pw2'];
$bool[1]=true;
$bool[2]=true;
if ($email[1] == $email[2])
{
echo " <b>Your e-mail's match.</b> <br/>";
}
else
{
echo "<b><font color='darkblue' size='4'>Your e-mail's do not match.</font></b></br>";
$bool[1]=false;
}
if ($pw[1] == $pw[2])
{
echo "<b>Your passwords match.</b>";
}
else
{
echo "<b><font color='darkred' size='4'>Your password's do not match.</font></b>";
$bool[2]=false;
}
if ($bool[1] == true && $bool[2] == true && $bool[3] == true && $bool[4] == true && $bool[5] == true && $bool[6] == true && $bool[7] == true && $bool[8] == true)
{
$msg='<font color="darkred" size="4">Welcome to Mythic Aeons</font>';
$subject='Activation Code';
$from='MythicAeons@yahoo.com.au';
$headers='From: '.$from;
mail($_POST['email1'],$subject,$msg,$headers);
echo '<font color="blue" size="4">Your Activation code & details have been e-mailed to you</font>';
}
?>
</body>
</html>
These are the errors
the ERROR: your username/password n so is my personal errors ignore them
Code: Select all
Notice: Undefined index: user in c:\program files\easyphp1-8\www\test\youhavebeene-mailed.php on line 22
Error: Your username must be no less then 5 characters long.
Notice: Undefined index: pw1 in c:\program files\easyphp1-8\www\test\youhavebeene-mailed.php on line 40
Error: Your password must be no less then 5 characters long.
Notice: Undefined index: pw2 in c:\program files\easyphp1-8\www\test\youhavebeene-mailed.php on line 55
Error: Your confirm password must be no less then 5 characters long.
Notice: Undefined index: user in c:\program files\easyphp1-8\www\test\youhavebeene-mailed.php on line 70
Notice: Undefined index: pw1 in c:\program files\easyphp1-8\www\test\youhavebeene-mailed.php on line 76
Notice: Undefined index: pw2 in c:\program files\easyphp1-8\www\test\youhavebeene-mailed.php on line 82
Notice: Undefined index: email1 in c:\program files\easyphp1-8\www\test\youhavebeene-mailed.php on line 93
Notice: Undefined index: email2 in c:\program files\easyphp1-8\www\test\youhavebeene-mailed.php on line 94
Notice: Undefined index: pw1 in c:\program files\easyphp1-8\www\test\youhavebeene-mailed.php on line 95
Notice: Undefined index: pw2 in c:\program files\easyphp1-8\www\test\youhavebeene-mailed.php on line 96
Posted: Sat Dec 02, 2006 5:35 pm
by Ollie Saunders
wrap all code that makes use of $_POST inside a condition such as this...
Re: hmm
Posted: Sat Dec 02, 2006 5:39 pm
by Zoxive
Code: Select all
<?php
if (isset($_POST['user']) && strlen($_POST['user']) < 5){
$bool[3]=false;
echo '<font color="blue" size="4">Error:</font><font color="blue" size="3"><i> Your username must be no less then 5 characters long.<br/></i></font>';
}else if (isset($_POST['user']) && strlen($_POST['user']) > 18){
$bool[6]=false;
echo '<font color="blue" size="4">Error:</font><font color="blue" size="3"><i> Your username must be no more then 18 characters long.<br/></i></font>';
}else{
echo '<b>Your username is the correct length.</b><br/>';
}
?>
or
Code: Select all
<?php
if(isset($_POST['user'])){
if (strlen($_POST['user']) < 5){
$bool[3]=false;
echo '<font color="blue" size="4">Error:</font><font color="blue" size="3"><i> Your username must be no less then 5 characters long.<br/></i></font>';
}else if (strlen($_POST['user']) > 18){
$bool[6]=false;
echo '<font color="blue" size="4">Error:</font><font color="blue" size="3"><i> Your username must be no more then 18 characters long.<br/></i></font>';
}else{
echo '<b>Your username is the correct length.</b><br/>';
}
}
?>
ole wrote:wrap all code that makes use of $_POST inside a condition such as this...
But if the user doesn't fill out some part of the form, he still would get notices..
Posted: Sat Dec 02, 2006 5:47 pm
by Ollie Saunders
But if the user doesn't fill out some part of the form, he still would get notices..
Not true. As long as you aren't the victim of an attacker sending something other than the intended form all fields will be defined. Empty fields have an empty string as their value.
Posted: Sat Dec 02, 2006 5:51 pm
by feyd
ole wrote:Not true. As long as you aren't the victim of an attacker sending something other than the intended form all fields will be defined. Empty fields have an empty string as their value.
Except with check boxes, radio button groups and multiple select boxes too, I believe.
Posted: Sat Dec 02, 2006 6:05 pm
by Ollie Saunders
Except with check boxes, radio button groups and multiple select boxes too, I believe.
Ah yes, I forgot about that one. I hacked that problem away using a hidden value in my library.
You should use issets lots anyway in case you are attacked. Consider how easily a GET form is spoofed.
Posted: Sat Dec 02, 2006 7:17 pm
by Mythic Fr0st
nvm, some reason it started working
ALSO how do i check if a check box has been checked or not
(isset)