this is my first experience working with PHP to bear with me. I wrote a form handler to process data on my website and installed an apache server to run it on. Everything works fine until I submit the form, and the code either appears on the following page or displays a blank page. I’m not sure if this is an issue in my code or the way I stored it in htdocs. below is a snippet of my code:
Code displaying usually means the file does not have a .php file extension, assuming that Php is actually installed and the file is running on a server.
The main problem is that you are depending on the name of a button to be submitted in order for your script to work. This will completely fail in certain cases such as yours. You need to check the Request Method instead.
You are also sending a field named name-last that does not exist in your code.
Okay, I updated the name of the button and changed it in the request method but am still getting sent to a blank page. Is it something other than the name that should be changed? Also, thanks for pointing out the error in the last-name, I have updated that too.
What is being stated, your code depends on a specific button being in the transfer object. You don’t want to use that.
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
// a POST method or form submission sent the user here
} else {
// you came here on your own or the form method is wrong.
}
You are opening the form page (and therefore the form processing page) through the file system, not through a URL. The URL you use to open the form should be similar to - http:/localhost/deinproject/Einstein Design/send.php (if your form and form processing code are on separate pages, you need to put them both on the same page.)
If so you should read the documentation of WAMP and find out which directory the DocumentRoot is of your webserver. very likely something as C:\wamp64\htdocs. But i am not sure since i do not use WAMP. If you know where your DocumentRoot is that is also the place where you must store your php files. For example if C:\wamp64\htdocs is your DocumentRoot and you save a php file there which you call test.php then you should type in your in your browsers URL bar: http://localhost/test.php