big problem, lots of undefined indexes help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

big problem, lots of undefined indexes help

Post 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?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

isset() and/or array_key_exists() may be of interest.
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

ty

Post by Mythic Fr0st »

Thanks, but how would I use it, :?:
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

Code: Select all

if(isset($var)){
    print $var;
}
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

hmm

Post by Mythic Fr0st »

Burrito | Please use

Code: Select all

,

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

,

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]
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

is there perhaps another instance of $_POST['user']?

what you have, by all accounts, should work.
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

hmm

Post 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
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

wrap all code that makes use of $_POST inside a condition such as this...

Code: Select all

if (!empty($_POST)) { }
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: hmm

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

Code: Select all

if (!empty($_POST)) { }
But if the user doesn't fill out some part of the form, he still would get notices..
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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.
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

Post by Mythic Fr0st »

nvm, some reason it started working

ALSO how do i check if a check box has been checked or not

(isset)
Post Reply