# Undefined index warning when the form loads for the first time in PHP

Source: https://coursesweb.net/forum/t/undefined-index-warning-when-the-form-loads-for-the-first-time-in-php/
Site: CoursesWeb Forum, category Error Messages Explained
Published: 2026-12-01. Updated: 2026-12-02. Replies: 3.

## Question by Lin W., 2026-12-01

Following on from my contact form (thank you to everyone who helped). Now I have an order form on the same page that shows what the customer typed again if something is missing. It works after you press the button. But the very first time the page opens, before anybody has typed anything, I get this yellow line at the top:

`Notice: Undefined index: name in /home/site/order.php on line 12`

and one more for "phone". The code on line 12 is:

```php
<input type="text" name="name" value="<?php echo $_POST['name']; ?>">
<input type="text" name="phone" value="<?php echo $_POST['phone']; ?>">
```

After the customer presses Send, the page fills in the fields and the notice is gone. It is only the first visit that shows it.

I know a notice is not a fatal error, and the page still works, but customers can see it and it looks sloppy for the restaurant. My host runs an older PHP version. What is the correct way to fix this, and not just hide it?

## Reply 1 by Ewa P., 2026-12-01

On the first visit nobody has submitted the form yet, so $_POST is empty and the key "name" does not exist. PHP is warning you that you are reading something that is not there. Check it with isset() before you print it.

## Reply 2 by Zaid M., 2026-12-01

just put an @ in front, like echo @$_POST['name']; the notice goes away instantly. i do that everywhere in my game code. nobody sees the warnings and the page looks clean, what is the downside?

## Reply 3 by Marisa T., 2026-12-02

A small edge case to keep in mind: if you use empty() instead of isset(), a value of "0" counts as empty. For a name field it will not matter, but for a quantity field it could. Which one do you want here, Lin?

---
Cite as: CoursesWeb Forum, "Undefined index warning when the form loads for the first time in PHP", https://coursesweb.net/forum/t/undefined-index-warning-when-the-form-loads-for-the-first-time-in-php/, accessed 2026-12-02.
