PDA

View Full Version : _post



gauri_agr
24 Jul 2009, 04:29 PM
Hi All,

I was trying to understand _POST. I have used it blow

---------------
Paper.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0

Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title> Exam 1</title>
<body>

<form action="http://localhost/answer.php"

method="post" target="_self" >

</br>Please write your name </br>

<input type ="text" name="name">
<br>Qesution 1 What is the name of our country<br>
<br><input type="radio" name="Question1" value="india"

> India
<br >
<input type="radio" name="Question1" value="us" > US
</br>

<br>Qesution 2 What is your relegion<br>
<input type="radio" name="Question2" value="hindu">

Hindu
<br>
<input type="radio" name="Question2" value="Muslim" />

Muslim
<br>
<br><input type ="submit" value="done">
</form>


</body>
</head>
</html>
-------------------------
answer.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<?php
$Question1 = $_POST["Question1"];
$Question2 = $_POST["Question2"];
$name=$_POST["name"];

?>

<head>
<title> Exam 1</title>
<body>
<?php
echo "<br>My Name is <br>";
echo "$name"."<br>";
echo $Question1."<br>";
echo " I want to display with variable i <br> <br>";
echo $_POST[0];

echo "<br>".$Question2."<br>";

$file=fopen("answer.txt","a+") or exit("Unable to open file!");
fwrite($file,$Question1."\n");
fwrite($file,$Question2."\n");
fclose($file);


?>


</body>
</head>
</html>

----

right now I have just two question so I am acessing all the answer( ie. value) with with their name using _POST. What If I have many questions ,then how can I acess all teh values from _POST. I am new to PHP. I want to use something like _POST[i] ...please guide me

Thanks in advanced
Gauri

is_numeric
25 Jul 2009, 08:21 AM
$_POST is an array collection

as long as the method is set to POST then you can access all submitted form field data


$_POST['formFieldId'];