By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,254 Members | 2,386 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,254 IT Pros & Developers. It's quick & easy.

Method POST

P: 18
I am working thru the book PHP, MySQL and Apache from the Sams teach yourself library. On page 202 the exercise it to create an HTML input screen and then pass the variables to php. When I try my it opens my PHP listing but does not display it as a website. Any help would be appreciated.
Jan 20 '12 #1
Share this Question
Share on Google+
37 Replies


Dormilich
Expert Mod 5K+
P: 8,639
how do you open it?
Jan 20 '12 #2

P: 18
Dormilich this is the line of code in the html form form action="send_simpleform.php" method="POST". What happens next then it that the .php file is opened for editing instead of being the web page parroting what was written the html form.

I went to the book CD to copy the code from there thinking maybe I had a typing error that I wasn't seeing. Those files work the same as mine.

Suggestions?!
Jan 21 '12 #3

Dormilich
Expert Mod 5K+
P: 8,639
are you calling the file via http & localhost?
Jan 23 '12 #4

P: 18
this is the line from the html page which "calls" the php code.

<form action="send_simpleform.php" method=post>

all pages are being displayed in the localhost server. I am using Apache for this.

If I change the entire process to be just one php text file with php code list on the top with the html code listed below with this command <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="POST"> in the html the process works.

So I am thinking it is something to do with the act of existing one file to go to another one. It is finding the called file just isn't running it. Any suggestions????

<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="POST">
Jan 23 '12 #5

Dormilich
Expert Mod 5K+
P: 8,639
but in general, .php files are behaving as expected?
Jan 23 '12 #6

P: 18
yes they are. My problem started when I tried to send variables from a Html page to a php page.

These are my first attempts at using this technology. I am just working through excerises in a book to learn. Everything has worked thus far with the exception of branching out from a html to php. My thoughts are at this time that being able to do this branching would prove very powerful and useful.

thanks in advance for your response and help.
Jan 23 '12 #7

Dormilich
Expert Mod 5K+
P: 8,639
maybe it's time to look at your code. usually there is no problem in calling PHP scripts from HTML (and to be precise, every web page, be it created by PHP or any other server script, ends up as HTML).
Jan 23 '12 #8

P: 18
here is the code (from the book examples....)

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>A simple HTML form</title>
  4. </head>
  5. <body>
  6. <form action="send_simpleform.php" method="POST">
  7. <p><strong>Name:</strong><br/>
  8. <input type="text" name="user"></p>
  9. <p><strong>Message:</strong><br/>
  10. <textarea name="message" rows="5" cols="40"/></textarea></p>
  11. <p><input type="submit" value="send"/></p>
  12. </form>
  13. </body>
  14. </html>
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. echo "<p>Welcome <b>".$_POST["user"]."</b>!</p>";
  3. echo "<p>Your message is:<br/><b>".$_POST["message"]."</b></p>";
  4. ?>
and again the html page does open the php file but it is not displaying as a page but opens it for editing the php file.

thanks!
Jan 23 '12 #9

Dormilich
Expert Mod 5K+
P: 8,639
which browser do you use?
Jan 23 '12 #10

P: 18
internet explorer - apache server set as localhost
Jan 23 '12 #11

Dormilich
Expert Mod 5K+
P: 8,639
try Firefox or Chrome. I'm not trusting IE here.
Jan 23 '12 #12

P: 18
I really need it to work in Internet Explorer. I don't have the other browsers.
Jan 23 '12 #13

Dormilich
Expert Mod 5K+
P: 8,639
it would help to know whether the problem is server-side or IE.
Jan 24 '12 #14

P: 18
Sadly, the exact same thing happens in Chrome....instead of running the PHP code it opens the code in a text editor (note pad).
Jan 24 '12 #15

Dormilich
Expert Mod 5K+
P: 8,639
OK, this seems like a header problem.

try the following
- HTML code as is
- send_simpleform.php:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. header("Content-Type: text/plain");
  3. echo "done";
  4. ?>
if that behaves the same (quite probable) you need to check the Apache or IIS configuration (whichever server you have). it might be that PHP is not registered as handler.

and while in Chrome, you can check the file's headers in the developer tools.
Jan 24 '12 #16

P: 18
thanks, but still reacting the same.
Jan 24 '12 #17

Dormilich
Expert Mod 5K+
P: 8,639
what about the file headers in chrome? (Tools > Developer Tools > Network tab)
Jan 24 '12 #18

P: 18
it might be that PHP is not registered as handler.

where would I find that out?

I did run it in chrome with the devoloper tools on but I'm not sure what I am looking for.
Jan 24 '12 #19

Dormilich
Expert Mod 5K+
P: 8,639
it might be that PHP is not registered as handler.
where would I find that out?
in the server configuration file(s).


I did run it in chrome with the devoloper tools on but I'm not sure what I am looking for.
you're looking for the network tab (blue globe with LAN connector). next, click on the file name send_simpleform.php. now the panel changes from a table to some text. the first tab of the text (which should be open now) should read "Headers". look under "Response Headers" for "Content-Type". this should be text/html, were it working. other types may cause the browser to download the file (e.g. application/octet-stream)
Jan 24 '12 #20

P: 18
Thanks for all this useful information - pretty slick and, being new to the scene, didn't even realize it existed! But on to the problem at hand.

when the html code is in the developer mode the method listed is GET even though the code inside says POST.

The PHP page lists the content type as text-plain.

The entire process though is no longer opening a separate window at least in the chrome.

Any other ideas???

Thanks!
Jan 24 '12 #21

Rabbit
Expert Mod 10K+
P: 12,366
You've said other PHP pages have worked fine. Try those pages again and post the PHP for one of those files.
Jan 24 '12 #22

P: 18
I've never had a POST PHP page work. As you can tell I'm just a beginner.

The examples where the PHP code is listed within a Html page work.

My setup will preform the statement below properly - just bring that up since it is getting the format to use from another php file.

$format = include("local_format.php")

Dormilich walked me thru using chrome to display the html code and I find the GET vs POST command a bit alarming - spoken with very limited knowledge - I would have expected that to be POST.

Thanks for your help.
Jan 24 '12 #23

Dormilich
Expert Mod 5K+
P: 8,639
$format = include("local_format.php")
include() is not a function but a language construct. the correct syntax would be include "local_format.php";
if you want a file’s content in a string use file_get_contents().

Dormilich walked me thru using chrome to display the html code and I find the GET vs POST command a bit alarming - spoken with very limited knowledge - I would have expected that to be POST.
GET/POST command?
Jan 24 '12 #24

P: 18
when the html code is in the developer mode the method listed is GET even though the code inside says POST.

this is what I am referring to.
Jan 24 '12 #25

Dormilich
Expert Mod 5K+
P: 8,639
the HTML page itself must be GET because you call it via URL.
Jan 25 '12 #26

P: 18
well I am still at a stand still - cannot get this basic command to function.

any other suggestions???

I do notice on the failures that I receive that the secondary PHP page type is coming in as plain/text - if I understand you correctly from prior post that should be html - how would I change that?

Thanks for all your help, I do appreciate but it's very hard not to be frustrated.
Jan 25 '12 #27

Dormilich
Expert Mod 5K+
P: 8,639
I do notice on the failures that I receive that the secondary PHP page type is coming in as plain/text - if I understand you correctly from prior post that should be html - how would I change that?
if you used the code from post #16, that's correct. though normally a plain text file should be displayed in the browser (unless you told it to download the file).

otherwise could you write down all the headers you get?

regarding your server settings, which server do you use? (I only know Apache somewhat)
Jan 25 '12 #28

P: 18
file:///C:/Program%20Files/Apache%20Software%20Foundation/Apache2.2/htdocs/simpleform.html

for the php form it is....
file:///C:/Program%20Files/Apache%20Software%20Foundation/Apache2.2/htdocs/send_simpleform.php

however, shouldn't the second one be localhost/send_simpleform.php?

because if I change the address to that then I get a webpage with done on it.
Jan 25 '12 #29

Dormilich
Expert Mod 5K+
P: 8,639
if you want to use PHP, never use the file: protocol anywhere (not even in the calling HTML page)! if you do, .php is treated as text because the file system recognioses PHP files only as text.
Jan 25 '12 #30

P: 18
I didn't change anything to read those URL in my samples - just something that I noticed.

Maybe I'm not understanding what you mean by headers. My code has changed since the beginning with the exception of the lines you wanted me to add to send_simpleform.php.

I am using an apache server.
Jan 25 '12 #31

Dormilich
Expert Mod 5K+
P: 8,639
the URL of your HTML form should read:
http://localhost/simpleform.html

with headers I mean HTTP headers.
Jan 25 '12 #32

P: 18
finally success! I've been opening the html pages from the actual folder they are in.

When I type the URL using the localhost then they run the php page. Boy my laziness sure created a huge problem for me.

Thanks for all your help and patience - I know you must be just rolling your eyes big time. If it makes you feel any better at least you taught me a bunch of stuff!

Thanks again!
Jan 25 '12 #33

Dormilich
Expert Mod 5K+
P: 8,639
rest assured that you're not the first one with that problem, though I may point to posts #2 & #4 where I asked exactly for that.
Jan 25 '12 #34

P: 18
yep, and now when I read those two post they make sooo much sense! You've taught me much in these past couple of days!

thanks again!
Jan 25 '12 #35

Dormilich
Expert Mod 5K+
P: 8,639
and that's just scratching the surface ...
Jan 25 '12 #36

P: 13
Make sure that you are using "localhost" to host your related php and html files. Do not open the html page direclty by double-clicking. Also make sure that your Appache server is running soundly.
Jan 25 '12 #37

Dormilich
Expert Mod 5K+
P: 8,639
@Kadir Razu: you are aware that this problem is already solved?
Jan 25 '12 #38

Post your reply

Sign in to post your reply or Sign up for a free account.