I am writing a PHP application to store telephone directory entries in a MySQL database. However, with my current validation it displays an error message even if all information is filled out.
I was hoping someone could help. Here is my validation code:
if (empty($_POST['first_name']) || empty($_POST['last_name']) || empty($_POST['address'])
|| empty($_POST['city']) || empty($_POST['state']) || empty($_POST['zip']) ||
empty($_POST['telephone']))
echo "<p>You must fill out all fields! Click your browser's
Back button to return to the Telephone Directory form.</p>";
else if (is_numeric($_POST['zip']) === FALSE || is_numeric($_POST['telephone']) === FALSE)
echo "<p>You must enter numeric values for the zip code and phone number.</p>";
I've looked it over quite a bit and I think the guilty party is the 'telephone' field but I'm not 100% sure. Here is the HTML:
<h2>New Entry</h2>
<form method="POST" action="TelephoneDirectoryWrite.php">
<p>First Name <input type="text" name="first_name" /></p>
<p>Last Name <input type="text" name="last_name" /></p>
<p>Address <input type="text" name="address" /></p>
<p>City <input type="text" name="city" /></p>
<p>State <input type="text" name="state" /></p>
<p>Zip <input type="text" name="zip" /></p>
<p>Phone Number <input type="text" name="telephone" /></p>
<p><input type="submit" value="Add Entry" /></p>