JohnJeans Posted January 6, 2015 Share Posted January 6, 2015 Hello everyone I'm trying to find out where is the problem in applying the PHP tutorial here on w3schools !!! in lesson validating an html form I apply it but it didn't work !!!! So I started from the beginning so I've created a very simple html form like this: <!DOCTYPE HTML> <html> <head> <title>th_1</title> <style> .error {color: #FF0000;} </style> </head> <body> <form method="post" action="tp_1.php"> <input type="text" name="Fname" ><span class="error"> * <?php echo $FnameErr;?></span> <p></p> <input type="submit" name="submit" value="Submit"> </form> </body> </html> and the tp_1.php is: <!DOCTYPE HTML> <html> <head> <title>tp_1</title> </head> <body> <?php // define variables and set to empty values $Fname = ""; $FnameErr = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["Fname"])) { $FnameErr = "Name is required"; } else { $Fname = test_input($_POST["Fname"]); } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> </body> </html> So, when I leave the text box blank instead I receive "Name is required" message next to the text box I receive Internal Server error..!!! Can anyone tell me where is the error..!!!!? Thank you all Link to comment Share on other sites More sharing options...
Ingolme Posted January 6, 2015 Share Posted January 6, 2015 If you're getting an internal server error then something's wrong with the server's configuration and it's not caused by PHP. 1 Link to comment Share on other sites More sharing options...
JohnJeans Posted January 6, 2015 Author Share Posted January 6, 2015 (edited) Thank you Foxy Mod, I called the hosting company and told them that they should configure their server to be able to read the php code when the server arrives to "<?php starting php code tags instead of ignore it completely because the form file is saved in html extension !! but they told me that this is not normal.to use php code into html document.!!!!!!! it's really ridiculous that they said that !!!! Because we need the php functions to validate the form input...!!! After i searched the internet I found this answer: "You can't run PHP in .html files because the server does not recognize that as a valid PHP extension unless you tell it to. To do this you need to create a .htaccess file in your root web directory and add this line to it: AddType application/x-httpd-php .htm .html" So, I applied it in .htaccess and it works fine but when I get back my original html form I found it is not working any more and I received 500 internal Server Error again !!! Then I got back to .htaccess and removed that line and save it to let my original html file works again but unfortunately it's not working any more !!! I'm lost !!! Thank you again Foxy Mod Edited January 6, 2015 by JohnJeans Link to comment Share on other sites More sharing options...
Ingolme Posted January 6, 2015 Share Posted January 6, 2015 A badly made htaccess file can cause an internal server error. Just give your files a ,php extension if you want to run PHP. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now