logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Coding & Scripting Corner View previous topic :: View next topic
Reply to topic   Topic: Setup to get HTML form data to PHP file on local server
Author
leaning



Joined: 10 Mar 2016
Posts: 3
Location: USA, GA

PostPosted: Fri 11 Mar '16 0:07    Post subject: Setup to get HTML form data to PHP file on local server Reply with quote

Ok, very new here. Here's what I did.

1. Downloaded XAMPP. Set up a local Apache server.
2. Created a directory C:/mylocalserver.
3. Changed the DocumentRoot and Directory in Apache's httpd.conf files to C:/mylocalserver.
4. Created an HTML webpage (welcome.html)and put that in the mylocalserver directory.
5. Created a PHP file (welcome.php) and put that in the mylocalserver directory.
6. When I double-click on the welcome.html file, it opens in Firefox. I input the name and e-mail and click the Submit button.
7. The webpage changes to show the code for welcome.php. (Is is supposed to do that??)
8. Now, on another tab in Firefox, I enter localhost/welcome.php.
9. It comes up to an error screen that says Welcome
Notice: Undefined index: name in C:\mylocalserver\welcome.php on line 4 and Your email address is:
Notice: Undefined index: email in C:\mylocalserver\welcome.php on line 5.

It's like the html file isn't sending anything to the php file. I don't know. If anyone has any ideas, I'm all ears. Regards, Leaning

welcome.html
Code:
<html><body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body> </html>


welcome.php
Code:
<html><body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body></html>




-Windows 10
-XAMPP for Windows 5.5.33 includes: Apache 2.4.17, MariaDB 10.1.10, PHP 5.5.33, phpMyAdmin 4.5.1, OpenSSL 1.0.2, XAMPP Control Panel 3.2.2, Webalizer 2.23-04, Mercury Mail Transport System 4.63, FileZilla FTP Server 0.9.41, Tomcat 7.0.56 (with mod_proxy_ajp as connector), Strawberry Perl 7.0.56 Portable
Back to top
olwo



Joined: 11 Mar 2016
Posts: 1
Location: Germany

PostPosted: Fri 11 Mar '16 11:04    Post subject: Reply with quote

Hello,

"6. When I double-click on the welcome.html file, it opens in Firefox. I input the name and e-mail and click the Submit button.
7. The webpage changes to show the code for welcome.php. (Is is supposed to do that??) "

Yes, thats what you said it should do.

The html-file sends data to the Server together with a call for the php-File. The data is found in the Array $_POST.

If you open welcome.php alone the Array is just empty (or better the array has no index-entry called name and email) and that is the reason for the error message.

So technicaly everything works as expected from my point of view Smile

Regards
Olaf
[/u]
Back to top
leaning



Joined: 10 Mar 2016
Posts: 3
Location: USA, GA

PostPosted: Fri 11 Mar '16 18:00    Post subject: Reply with quote

Olaf,

The welcome.php file does have the name and e-mail on it. It's supposed to say "Welcome John. Your email address is John@mail.com.". It just says "Welcome. you r email address is . and the two error messages. I don't think that's how it should work.

Any other ideas?

Regards,
John
Back to top
leaning



Joined: 10 Mar 2016
Posts: 3
Location: USA, GA

PostPosted: Sun 13 Mar '16 6:20    Post subject: Solved Reply with quote

I figured out what I was doing wrong.

To view/run/open the html file, I was going to the server directory and double-clicking the file name. And it would open like you'd expect, but it wouldn't be running.

In order to get it to run (which is what needs to happen), I now know I have to open a browser, and then type in localhost/welcome.html and then it will run as it should and the php part will work like it should.

So, double-click the filename to edit and view, but to run it, that file name(path) has to be entered in a browser.

(So, if someone else complains of undefined index errors, ask them how they are accessing the html file. Are they going to the directory and double-clicking it, or are they entering the file path into the browser's search bar.)

Hope this helps others.
Regards,
leaning
Back to top


Reply to topic   Topic: Setup to get HTML form data to PHP file on local server View previous topic :: View next topic
Post new topic   Forum Index -> Coding & Scripting Corner