For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > March 2004 > Newbie question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Newbie question
Gajo Csaba

2004-03-26, 11:12 pm

Hi!
I'm new to PHP, so this may be an easy question. I tried to make a
simple form-page, where the user enters his name, and on the following
page it says "Hello $name". What happens is that on the second page it
says soemthing like "unknown identifier $name".

I'm using apache 2 so that may be causing the problem, cause this is a
clear textbook example:

---------------------- first.php ----------------------
<html>
<head>
<title>First</title>
</head>
<body bgcolor="#ffffff" text="#000000" link="#cbda74"
vlink="#808040"
alink="#808040">
<form action="second.php" method="post">
<b>Whats your name?</b>
<input type="text" name="name" size="20" maxlength="20"
value=""><br>
<input type="submit" value="go!">
</form>
</body>

--------------- second.php --------
<html>
<head>
<title>Second</title>
</head>
<body bgcolor="#ffffff" text="#000000" link="#cbda74"
vlink="#808040"
alink="#808040">
<?
print "Hello $name!";
?>
</body>
</html>
Kim Steinhaug

2004-03-30, 3:31 pm

Well,

Could be some sort of debugging mode on the PHP running on the
server. On the other hand your script is depending on the fact that
GLOBALS are turned on, which - you shouldnt.

1)
Anywho - you form is using POST, so you should use this syntax :

$_POST["variable"], if using GET the equivilant is : $_GET["variable"]

2)
You should try to avoid putting variables inside quotes, unless you have
a good reason for is. Meaning
"Hello $variable";
should be written as :
"Hello " . $variable;

So the answer to your question would be, on the second page, and I also
prefer echo instead of print.

echo "Hello " . $_POST["name"] . "!";
or
echo 'Hello ' . $_POST["name"] . '!';

--
--
Kim Steinhaug
----------------------------------------------------------------------
There are 10 types of people when it comes to binary numbers:
those who understand them, and those who don't.
----------------------------------------------------------------------
www.steinhaug.com - www.easywebshop.no - www.webkitpro.com
----------------------------------------------------------------------
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com