Page 1 of 1

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

Posted: Sun Feb 03, 2008 8:15 am
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.

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

Posted: Sun Feb 03, 2008 8:27 am
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.

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

Posted: Sun Feb 03, 2008 8:40 am
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?

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

Posted: Sun Feb 03, 2008 3:03 pm
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.