scrgeek Posted January 15, 2018 Share Posted January 15, 2018 I have two test files set up as simple forms. For all practical purposes, they are identical with the exception of the how the php is called. Both files use the same php file to process the data. In the first case (test1.html), the php is called directly by the action method, and works: <form class="pWriteShort" id="contact" action="test.php" method="post"> The second case (test2.html) calls the php with an include statement and global $_SERVER call as below: <?php include '/test/test.php'; ?> <form class="pWriteShort" id="contact" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post"> In the second case, it leads to a server generated 404 error. I know I must be doing something stupid, but for the life of me, I can't find it. If further info is needed, the files are here: http://www.northfloridawoodworking.com/test/test1.html http://www.northfloridawoodworking.com/test/test2.html Thanks, in advance, for any help. Regards, Sam Rogers Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted January 15, 2018 Solution Share Posted January 15, 2018 I am surprised either one works as they are .HTML files and not .PHP (unless your server is unusually configured) If you want the form to call the same page you can just leave the action blank(action=""). Quote Link to comment Share on other sites More sharing options...
scrgeek Posted January 15, 2018 Author Share Posted January 15, 2018 I'm quite new to php. The html files are just the forms... the validation is php. Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 15, 2018 Share Posted January 15, 2018 (edited) The html files are just the forms... the validation is php. You have PHP code in the action attribute for an HTML page. That code will not get processed and the HTML page will not know what to do with it. Let me try to explain in a different way: When a user requests a page from a websesrver, the webserver will first check to see if that page exists. Then, determining on the type of page that it is and how the server is configured, it can do different things with that request. - When requesting a page with a .htm or .html page the server will simply send the raw file to the user as is and the browser will display the page to the user. - If the requested page has an extension of .php (or some other server-side language it is configured for), the server will find that file and then send it to the PHP process to execute the code in that page - then send the results of the output from that code to the user. So, on your HTML page with this: <form class="pWriteShort" id="contact" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post"> Since the page was not sent to the PHP processor (because it has the extension of HTML) the action in the HTML page will be <?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>. The browser cannot process PHP code and would not know where to send the form. Edited January 15, 2018 by Psycho Quote Link to comment Share on other sites More sharing options...
scrgeek Posted January 15, 2018 Author Share Posted January 15, 2018 So, can the php page contain html and render that properly and then send that to the client's browser? Please pardon my stupidity... I just started trying to learn this yesterday. On another note, I did not see the note to not post this in the welcome area, but I couldn't find an option to delete the post. I'm sorry for breaking the rules on my first post. Quote Link to comment Share on other sites More sharing options...
scrgeek Posted January 16, 2018 Author Share Posted January 16, 2018 Wow. Renamed the test2.html to test2.php. Worked like a charm. Thank you very much for your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.