Undefined index warning when the form loads for the first time in PHP
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:
Cite
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.Notice: Undefined index: name in /home/site/order.php on line 12and one more for "phone". The code on line 12 is:
<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?
Write something first.
Give people something to work with: at least 30 words on what happened and what you tried.
That is too long. Keep it under 6,000 characters.
Write the question as the title, 15 to 140 characters, no links.
Pick a category.
Add a name (2 to 40 characters, no links).
That email address does not look right.
That was quick. Read the thread, then try again.
The form expired. Reload the page and post again.
Something went wrong with the form. Reload and try again.
Please complete the check and post again.
Limit reached for now. Try again later.
This thread is closed to new replies.
This thread no longer accepts replies.
Something went wrong with the form. Reload and try again.
Post a reply or question first (name and email), then this browser can vote, edit and accept answers.
You cannot vote on your own post.
Only the author (within 30 days) or the forum team can do that.
That email already has an account. Use your sign-in link instead.
New accounts are paused for the moment. Try again later.
That was already posted.