Forum : Problems with forms
Brief description  about Online courses   join in Online courses
View abhishek  shukla 's Profile

Problems with forms

I having problems with forms .I tried running some programs.but they are not showing the correct output.One the program I tried running is in the text tutorial

<html>

<body>

<form action="index.php" method="POST">

Name: <input type="text" name="name" />

Age: <input type="text" name="age" />

<input type="submit" />

</form>

</body>

</html>





"index.php" file.



<html>

<body>

Hello <?php echo $_POST["name"]; ?>.<br />

You are <?php echo $_POST["age"]; ?> years old.

</body>

</html>


The output was

Hello
You are year old

i.e the form values are not getting printed .

I tried running similar programs but that too are not showing the form values .

<html><body>
<h4>Select your country</h4>
<form action="process.php" method="post">
<select name="country">
<option>India</option>
<option>USA</option>

</select>

<input type="submit" />
</form>
</body></html>

process.php


<?php
$country = $_POST['country'];
if($country=="India"){
echo "New Delhi is the capital of India<br />;
}
else
echo "Washington is the capital of USA";
?>

This too is not showing the correct output.
I am using wamp server and each files is placed in the correct directory
Asked by abhishek shukla | Nov 30, 2009 |  Reply now
Replies (4)
View sanjay s nair 's Profile
You are very welcome
Dec 8, 2009
View abhishek shukla 's Profile
Thanks , I was launching the html file directly . Now its working

Thanks a lot
Dec 6, 2009
View teacher siliconindia 's Profile
Hi Abhishek,

What Sanjay has replied is right. Try the steps which sanjay has mentioned and get back.

Regards
Dec 2, 2009
View sanjay s nair 's Profile
How are you accessing these files, I mean take the first case out of 2 you have given. You have to launch a web browser and type in the address bar "http://localhost/pathtourdirectory/thatpage.html" . Make sure you are not launching the html page directly. If this is not the problem in the second page try to print the POST array and see any values are passed in the POST array. <?php print_r($_POST); ?> . Check this and get back.
Nov 30, 2009