Jump to content

Archived

This topic is now archived and is closed to further replies.

cat_emma

simple php question

Recommended Posts

hello everybody

I am new here and to php

I want to use the POST method to display the information entered in an html form, i want to display it in a php page. but the problem is: when i submit the form, i get a box to download the php form instead of having it displayed in internet explorer

the code is bellow:

[code]<html>
<head>
<title> form 1 </title>
</head>

<body>
<form action="example_2-2.php" method="POST">
<P>Your name: <input type="text" name="name" /></P>
<P>Your age: <input type="text" name="age" /></P>
<P><input type="submit" /></P>

</form>
</body>
</html>[/code]

[u]php file[/u]

[code]Hello <?php echo $_POST['name'];?>
You are <?php echo $_POST['age'];?> Years old[/code]


So when I fill the form and submit, insted of getting the exmaple_2-2.php displayed, i get a box that asks me whether i want to open or download the .php file. When I choose open, I get it open in a txt format

I wonder what is the problem

I will be so greatful if you help me, this is almost the first obstacle I face in php : )

Thank you

Imane

Share this post


Link to post
Share on other sites
You will need to set up apache and php on your pc. If you don't do that, it will just treat php as a download. A great all-in-one package is xampp.

-Chris

Share this post


Link to post
Share on other sites
Could you be a little more explicit, what exactly is your problem?  Did you change the script so that instead of evaluating the form with example#.php you use your own script?  And is this new script just displaying itself as text instead of being processed?  If so the problem sounds like A) the file isn't .php or B) you didnt put the code in the absolutely necessary <?php ?> tags.  If I didn't address you're issue give us a little more information, it's hard to tell what the problem is.

Share this post


Link to post
Share on other sites
thank you Chris,

I am working with easyphp, and I alreayd tried php files and they open with internet explorer very fine

The problem rose when I used a form that have an action of displaying the php file

do you think of any other reason why this happens?

Share this post


Link to post
Share on other sites
I have included the code

In fact i took it from a tutorial that I am trying to practice

They show us in the tutorial how to use forms with POST method

I took it from: http://www.php.net/manual/en/tutorial.forms.php

What I am trying to do is: get name and age from a form and display in a php page a message that uses those parameters that I will get from the POST

maybe I am doing it the wrong way

help plz!

Share this post


Link to post
Share on other sites
How did you invoke your script. It must be invoked via a URL.  It can't be invoked by double clicking it.

Ken

Share this post


Link to post
Share on other sites
I invoke it by clicking the submit button of the form.htm page (I included its code in my first posting)

Share this post


Link to post
Share on other sites
Did you open it up THOUGH the browser or just double clicked it in the folder that it was in?

Share this post


Link to post
Share on other sites
Can you put this into a file called [b].htaccess[/b] in the same folder and try again:
[code]
AddType application/x-httpd-php .php .php3 .php4 .php5
[/code]

Share this post


Link to post
Share on other sites
u mean I create a file in www and name it htaccess, then put the code u gave e in it?

(sorry maybe my question is stupid, but I am in the first days of php)

Share this post


Link to post
Share on other sites
No problem, it's good you're learning.
Yeah put it in a file called [b].htacces[/b]. (Strange filename, it's just a prefix!)
Put my code in there and then you may need to reload EasyPHP.

Share this post


Link to post
Share on other sites
I found in the file written:

Order deny,allow
allow from 127.0.0.1
deny from all

so i just added the code u gave me, but i face the same problem...

Share this post


Link to post
Share on other sites
The naming of files with just an extension like ".htaccess" is directly related to the convention on UNIX operating systems and their dirivitives like Linux that hides any file that starts with a period from a normal directory listing. It's a form of rudimentary security.

The basic explanation of this is: these are files that "normal users" shouldn't have to play with, so if they can't see them when they do a directory listing, the don't know they are there, so they can't be fooled with.

Ken

Share this post


Link to post
Share on other sites
I thought I'd have a go incase the wrong headers were being sent to download etc.
Could you post the full url of the form page in the browser?

Share this post


Link to post
Share on other sites
Thanks ALLAH I found the solution

the problem is that I used to have the form in an htm extension while it should be php so that the server treats it I guess

i changed the .htm to .php and now it works

: ) tnx to all who tried to help

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.