Very Simple Code...But Won't Work...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MrRSMan
Forum Newbie
Posts: 20
Joined: Sun Feb 03, 2008 8:11 am

Very Simple Code...But Won't Work...

Post by MrRSMan »

Ok, my first page is;

Code: Select all

<html>
 
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Hello world</title>
</head>
 
<body>
<form method="post" action="print.php">
<p name="text">
Hello world.
</p>
<input type="submit" value="Click here" />
</form>
</body>
 
</html>
My second page, print.php is;

Code: Select all

<html>
 
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Print</title>
</head>
 
<body>
<?php echo $_POST["text"]; ?>
</body>
 
</html>
 
I can't get print.php to display the "Hello World" text...It's just a blank page.

NB: PHP is fully working on my server- this is not the problem.

Any suggestions? Thanks.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Re: Very Simple Code...But Won't Work...

Post by shiznatix »

its not printing anything because $_POST['text'] does not exist. The reason is that the <p> html tag is not a form element and won't be "submitted". You need to put it in a form field. Try changing the

Code: Select all

 
<p name="text">Hello World</p>
 
to this:

Code: Select all

 
<input type="text" name="text" value="Hello World" />
 
or this:

Code: Select all

 
<input type="hidden" name="text" value="Hello World" />
 
and then run it.
MrRSMan
Forum Newbie
Posts: 20
Joined: Sun Feb 03, 2008 8:11 am

Re: Very Simple Code...But Won't Work...

Post by MrRSMan »

Thanks shiznatix

But is there a way of displaying "Hello world" as text that actually shows up in the page?

I don't want the text to be in a form, but I need it so people can see it, so it can't be hidden.

Any more suggestions?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Very Simple Code...But Won't Work...

Post by califdon »

MrRSMan wrote:Thanks shiznatix

But is there a way of displaying "Hello world" as text that actually shows up in the page?

I don't want the text to be in a form, but I need it so people can see it, so it can't be hidden.

Any more suggestions?
The whole point of using $_POST (or $_GET, for that matter) is to obtain data from the user, so there's no point in not using a form, allowing the user to enter or change what is passed to the next script. If you already know what you want the script to use, just code that in the script. It sounds like you're learning to use PHP (good for you, it will be very valuable to you, I'm sure), so I strongly recommend that you learn what the purpose of each part of the language is, not reinforce incorrect ideas.
Post Reply