Why am I getting this error?

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
McManCSU
Forum Newbie
Posts: 22
Joined: Mon Apr 23, 2007 6:30 pm

Why am I getting this error?

Post by McManCSU »

Undefined index: thisEthernet

Here is the relevent code:

Where it is choking:

Code: Select all

function process()
...

if (($_POST[THIS_ETH] >= 0) && ($_POST[THIS_ETH] < getNumberEthPorts())) <== CHOKES HERE
	{
	    // Ethernet number is not valid (not sure how this could happen)
	    echo '<script language="Javascript">';
	    echo "alert('$no_ethnum ($_POST[THIS_ETH])')";
	    echo '</script>';
	    
	    $isError = true;
	}
...
Where THIS_ETH is set:

Code: Select all

function display()
...
echo $tab3 . '<select name="THIS_ETH" onChange="window.alert(\'' . $etheralertText.'\')"' . ">\n";
...
Where THIS_ETH is defined:

Code: Select all

function constants()
...
define('THIS_ETH', 'thisEthernet');
...
The funny thing is, is that in the error message, it prints the corrent value of the THIS_ETH!? See:

Code: Select all

Array
(
    [THIS_ETH] => 4
...
)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

<?php
define('foo', 'bar');
echo foo;

// but you have
echo '  foo  ';
?>
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Not exactly. Kind of the opposite actually.

Since you defined THIS_ETH as thisEthernet, $_POST[THIS_ETH] is actually $_POST['thisEthernet'], but there is not a 'thisEthernet' field being posted, thus, the index 'thisEthernet' does not exist in $_POST.

Either use $_POST['THIS_ETH'] or change your fieldname to 'thisEthernet.'
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

superdezign wrote:Not exactly. Kind of the opposite actually.
I meant
McManCSU wrote:echo $tab3 . '<select name="THIS_ETH" onChange="window.alert(\'' . $etheralertText.'\')"' . ">\n";
which actually is exactly like echo ' foo '; ;)
Post Reply