Undefined variable in "input" form tag

Hi, I am trying to fix this undefined variable notice.
It is about a form with many input field, where a user post a new ad.

The code of the first input field is:

<b><?php echo $lang['POST_ADTITLE']; ?>:</b> <br />
                  <input name="adtitle" type="text" id="adtitle" size="40" maxlength="100" value="<?php echo $data['adtitle']; ?>" />

This get me undefined variable notice for "data".

I thought to use a way an expert suggested me before, for an undefined index error; I would fix so:

<b><?php echo $lang['POST_ADTITLE']; ?>:</b> <br />
                  <input name="adtitle" type="text" id="adtitle" size="40" maxlength="100" value="<?php echo isset($data['adtitle'])? $data['adtitle'] : ''; ?>" />

It seems to work. I want to know if it is correct and if it is safe to use it as a rule for the other input fields of the form.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ashish PatelCommented:
For vairables like $data in your case which can have value sometimes you should always check using isset before using those type of variables. But for those variables which you know are always set, you need not require to use this function isset.
Beverley PortlockCommented:
It should be OK. The only thing you might need to consider is using htmlspecialchars.

isset($data['adtitle'])? htmlspecialchars($data['adtitle'], ENT_QUOTES) : '';

which stops quotes from messing up your code

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jimgordonAuthor Commented:
If I just use "isset", then - if form can't be submitted because you didn't enter all required field - I don't get the previous entered data in the form field, but just a number "1". If I use the other way I posted above, I get a blank page on submit, instead... which is the correct way to use variable in input field without getting undefined variable/index errors?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.