-1

I have a page that is submitting data to itself, and the code I have is working, but the problem is when I load my page this error Notice: Undefined index: submitted in is on the page when I get there. However, once I give it the data and click submit, the error goes away and everything else goes smoothly. Any idea how to get rid of this?

<form method="POST" action="contactInfo.php">
<center>
Name: <input type="text" name="name"/>
Email: <input type="text" name="email"/> 
<input type ="submit" name="submitted" value="Submit" /> <br />
<?php
$formSubmitted = $_POST['submitted'];
if ($formSubmitted)
{
  echo "Thank you for your information.";
} ?>
Arthur Swails
  • 169
  • 14
Brit24
  • 65
  • 8

1 Answers1

2

$_POST['submitted'] doesn't exist yet until you submit the page. When visiting the page initially, it does not exist.

$formSubmitted = isset($_POST['submitted']);

Emery King
  • 3,550
  • 23
  • 34