I am new to PHP and I am trying to make a contact us form that will perform validation and will display an error if any of the fields are not entered correctly.
I tried following this tutorial W3schools php example
so this is how my form looks like
<h2>PHP Form Validation Example</h2>
<p><span class="error">* required field.</span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Name: <input type="text" name="name">
<span class="error">* <?php echo $nameErr;?></span>
<br><br>
E-mail: <input type="text" name="email">
<span class="error">* <?php echo $emailErr;?></span>
<br><br>
Website: <input type="text" name="website">
<span class="error"><?php echo $websiteErr;?></span>
<br><br>
Comment: <textarea name="comment" rows="5" cols="40"></textarea>
<br><br>
Gender:
<input type="radio" name="gender" value="female">Female
<input type="radio" name="gender" value="male">Male
<span class="error">* <?php echo $genderErr;?></span>
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
but I get an error saying
Error 404 - Not Found
The document you are looking for may have been removed or re-named. Please contact the web site owner for further assistance.
and my url changes to this
my domain name/%3C?php%20echo%20htmlspecialchars($_SERVER[
what am I doing wrong here? Also if this is not the right approach, can someone make a suggestion how can I display the error messages and success messages after validating and sending the email via PHP?
Update:
Ok, so first of all, the problem was the file extension so thank you Chris for your helpful comment. If you want, add your comment as an answer and I will select it as a correct answer.
Second. I had a problem when upon changing the extension and my href attributes, the server was still taking me to contactUS.html page instead of contactUs.php page. The problem was that my links were generated in JavaScript and for some reason, my browser was not using the updated javaScript files. I solved this by clearing my cookies.