Jump to content


Photo

simple php question


  • Please log in to reply
17 replies to this topic

#1 cat_emma

cat_emma
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 12 July 2006 - 07:39 PM

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:

<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>

php file

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


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

#2 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 12 July 2006 - 07:43 PM

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

#3 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 12 July 2006 - 07:45 PM

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.
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#4 cat_emma

cat_emma
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 12 July 2006 - 07:47 PM

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?

#5 cat_emma

cat_emma
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 12 July 2006 - 07:52 PM

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/m...orial.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!

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 12 July 2006 - 07:52 PM

How did you invoke your script. It must be invoked via a URL.  It can't be invoked by double clicking it.

Ken

#7 cat_emma

cat_emma
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 12 July 2006 - 07:55 PM

I invoke it by clicking the submit button of the form.htm page (I included its code in my first posting)

#8 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 12 July 2006 - 07:56 PM

Did you open it up THOUGH the browser or just double clicked it in the folder that it was in?

#9 cat_emma

cat_emma
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 12 July 2006 - 07:57 PM

i am putting the file in the www, so i opened the form.htm from the localhost/...

#10 cat_emma

cat_emma
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 13 July 2006 - 08:32 PM

any help plz?

#11 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 13 July 2006 - 08:37 PM

Can you put this into a file called .htaccess in the same folder and try again:
AddType application/x-httpd-php .php .php3 .php4 .php5

<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#12 cat_emma

cat_emma
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 13 July 2006 - 08:47 PM

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)

#13 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 13 July 2006 - 08:51 PM

No problem, it's good you're learning.
Yeah put it in a file called .htacces. (Strange filename, it's just a prefix!)
Put my code in there and then you may need to reload EasyPHP.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#14 cat_emma

cat_emma
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 13 July 2006 - 09:01 PM

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...

#15 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 13 July 2006 - 09:01 PM

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

#16 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 13 July 2006 - 09:06 PM

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?
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#17 cat_emma

cat_emma
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 13 July 2006 - 11:20 PM

the full url of the form is

C:\Program Files\EasyPHP1-8\www\form1.htm



#18 cat_emma

cat_emma
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 15 July 2006 - 08:10 PM

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






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users