/    Sign up×
Community /Pin to ProfileBookmark

Php Not Showing Up

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:

[code]
<!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>
[/code]

And I have this code for my php portion:

[code]
<!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>
[/code]

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

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@chrysJun 30.2005 — You should use method="post" for this.

Your code looks exactly right...
Copy linkTweet thisAlerts:
@bokehJun 30.2005 — You should use method="post" for this.[/QUOTE]Why?
Copy linkTweet thisAlerts:
@BeachSideJul 01.2005 — 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...
[code=html]
Enter your name: <input type="text" name="name" /><br>
Enter your age: <input type="text" name="age" />
<input type="submit" />
[/code]


It should be...
[code=html]
Enter your name: <input type="text" name="name"><br>
Enter your age: <input type="text" name="age">
<input type="submit">
[/code]
Copy linkTweet thisAlerts:
@SpectreReturnsJul 01.2005 — 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:
[code=php]
print_r($_GET);
[/code]

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.
Copy linkTweet thisAlerts:
@BeachSideJul 01.2005 — BTW I like to do stuff like this all in one page, makes it easier for me. I revised your code a bit...
<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;?php if(!empty($_GET)) { ?&gt;
Welcome &lt;?php echo $_GET['name']; ?&gt;.&lt;br /&gt;
You are &lt;?php echo $_GET['age']; ?&gt; years old!
&lt;?php } else { ?&gt;
&lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" name="ageForm" method="get"&gt;
Enter your name: &lt;input type="text" name="name"&gt;&lt;br&gt;
Enter your age: &lt;input type="text" name="age"&gt;
&lt;input type="submit" value="Submit"&gt;
&lt;/form&gt;
&lt;?php } ?&gt;
&lt;/body&gt;
&lt;/html&gt;


That works for sure.
Copy linkTweet thisAlerts:
@SheldonJul 01.2005 — 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
×

Success!

Help @The_Little_Guy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...