Problems with undefined index using a selection box

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
thallish
Forum Commoner
Posts: 60
Joined: Wed Mar 02, 2005 11:38 am
Location: Aalborg, Denmark

Problems with undefined index using a selection box

Post by thallish »

Hi I got problems with $_POST and a selection box. I get following error and i can't seem to figure out what can be wrong. Can somebody please help me?

Here's my error message:

Code: Select all

PHP Notice: Undefined index: profile in C:\www\webroot\kompetencesystem\101.tmp on line 24
and here's my code:

Code: Select all

<?php
include("framework.php");

frameworkTop();
?>
<p class="header">Rediger medarbejderprofil</p>
<p>Her er det muligt at redigere en given medarbejderprofil.</p>

<form action="<?php echo $_SERVER&#1111;'PHP_SELF'];?>" method="post">

<p>Vælg hvilken del af profilen du vil ændre: <br />
<select name="profile">
	<option value="person">Personoplysninger</option>
	<option value="uddannelse">Uddannelse</option>
	<option value="teknisk">Teknisk erfaring</option>
	<option value="projekt">Projekt erfaring</option>
</select>

<input type="submit" value="Vælg" />
</p>
</form>

<?php
$profile = addslashes($_POST&#1111;'profile']);
 
 
frameworkBottom(); 
 
    
?>
regards
thallish
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

when the page is first requested, there are no post variables.. isset() may help you.
thallish
Forum Commoner
Posts: 60
Joined: Wed Mar 02, 2005 11:38 am
Location: Aalborg, Denmark

Post by thallish »

that you'll have to explain. :oops: How will that help me? isn't that just for checking?

regards thallish
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$profile = (isset($_POST&#1111;'profile']) ? addslashes($_POST&#1111;'profile']) : '');
pretty simple huh? :)
thallish
Forum Commoner
Posts: 60
Joined: Wed Mar 02, 2005 11:38 am
Location: Aalborg, Denmark

Post by thallish »

excellent!!!

yup that was pretty simple! thanks a lot!

i never seen that before but i'll sure remember it now :wink:

regards thallish
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if you want to learn how that works.. search for ternary operator on php.net or here..
thallish
Forum Commoner
Posts: 60
Joined: Wed Mar 02, 2005 11:38 am
Location: Aalborg, Denmark

Post by thallish »

I will

regards thallish

:)
Post Reply