Hi!
In the following code-

<?php
header('Cache-Control:no-cache');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="<?php echo($_SERVER['PHP_SELF']);?>">

  <p>
    <label>Name:
      <input type="text" name="txt" id="txt" value="<?php $_POST['txt'];?>" />
    </label></p>
  <p>
    <input type="submit" name="b1" id="b1" value="Submit" />
  </p>
</form>

<hr />

<?php
//form handler

if(isset($_POST['b1']))
				{
					echo($_POST['txt']);
					
				}
				else
				{
					echo("Enter a value");
				}

?>

</body>
</html>

in this form, i am not able to understand why we have to use the value attribute for the textfield-

<input type="text" name="txt" id="txt" value="<?php $_POST['txt'];?>" />

don't we know that the $_POST variable refers to the value of the textfield? so why set the value attribute again?

Actually that code does nothing. It should be

<?php echo $_POST['txt'] ?>

Anyway, the reason that it would have been in there is if there was validation happening on that page then the forms would be repopulated so a user would not have to re-type.

ty for the reply

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.