simple undefined index 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
paulmilner
Forum Newbie
Posts: 2
Joined: Mon Aug 23, 2010 5:38 am

simple undefined index error

Post by paulmilner »

Hi
I have a line in a page which recieves form info from a form page

Code: Select all

$additional_info1 = $_REQUEST['additional_info1'] ;
the problem is, if the form which posts to this page does not have the form field 'additional_info1' then it throws up an undefined index error.

How can I stop this error without having to include the 'additional_info1' form field on the form page. This is one of many form fields which react in this way which I would like to only add only on specific pages which post to this php script
Thanks
Paul M
shawngoldw
Forum Contributor
Posts: 212
Joined: Mon Apr 05, 2010 3:38 pm

Re: simple undefined index error

Post by shawngoldw »

Code: Select all

$additional_info1 = isset($_REQUEST['additional_info1'] ) ? $_REQUEST['additional_info1']  : "";

If it isn't submitted $additional_info1 will equal ""



Shawn
paulmilner
Forum Newbie
Posts: 2
Joined: Mon Aug 23, 2010 5:38 am

Re: simple undefined index error

Post by paulmilner »

Thanks Shawn
That sorted it

Paul M
Post Reply