Click to See Complete Forum and Search --> : Php Not Showing Up


The Little Guy
06-30-2005, 02:26 PM
I am just starting to learn php, so Im not sure how to make this work. Im not sure if this is something to do with my server or not. Any ways, here is my problem.

I have this code for my html portion:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>

<form action="welcome.php" method="GET">
Enter your name: <input type="text" name="name" /><br>
Enter your age: <input type="text" name="age" />
<input type="submit" />
</form>

</body>
</html>

And I have this code for my php portion:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
Welcome <?php echo $_GET["name"]; ?>.<br />
You are <?php echo $_GET["age"]; ?> years old!
</body>
</html>


As you should know it should print something like this:
Welcome John.
You are 28 years old!

But this is what it actually prints:
Welcome .
You are years old!

Anyone know how to fix this problem?

By the way I used Post and Get

chrys
06-30-2005, 02:53 PM
You should use method="post" for this.

Your code looks exactly right...

bokeh
06-30-2005, 03:38 PM
You should use method="post" for this.Why?

BeachSide
06-30-2005, 11:37 PM
Oh and btw this probably has nothing to do with your problem but this is incorrect syntax. You are using xHTML style tags in an HTML page...

Enter your name: <input type="text" name="name" /><br>
Enter your age: <input type="text" name="age" />
<input type="submit" />


It should be...

Enter your name: <input type="text" name="name"><br>
Enter your age: <input type="text" name="age">
<input type="submit">

SpectreReturns
07-01-2005, 12:33 AM
Nevermind chrys. It isn't sensitive data so it doesn't matter if you use GET. Make sure your superglobals are set. Put in this code, and see if it returns anything:

print_r($_GET);

If it returns an array, then you're ok. If it doesn't you're in trouble.

Also, try setting error_reporting to E_ALL. That might help.

BeachSide
07-01-2005, 12:44 AM
BTW I like to do stuff like this all in one page, makes it easier for me. I revised your code a bit...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<?php if(!empty($_GET)) { ?>
Welcome <?php echo $_GET['name']; ?>.<br />
You are <?php echo $_GET['age']; ?> years old!
<?php } else { ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="ageForm" method="get">
Enter your name: <input type="text" name="name"><br>
Enter your age: <input type="text" name="age">
<input type="submit" value="Submit">
</form>
<?php } ?>
</body>
</html>


That works for sure.

Sheldon
07-01-2005, 04:35 AM
I like using a seperate page, makes me think my site is better than it is, i would rather use POST than GET so the url doesnt show the data, incase of bookmarks causing errors, else the code looks good. AND have a great weekend! it is mine now friday 9:47 off tp the pub!


Sheldon