Get text input value from a form in PHP

Description

The following code shows how to get text input value from a form.

Example


       //from   www. j a  va  2 s.c  o  m
<?php
$num_to_guess = 99;
$message = "";
if ( ! isset( $guess ) ){
   $message = "Welcome to the guessing machine!";
}elseif( $guess > $num_to_guess ){
   $message = "$guess is too big!";
}elseif( $guess < $num_to_guess ){
   $message = "$guess is too small!";
}else {
    $message = "Well done!";
}
?>
<html>
<head>
<title>A PHP number guessing script</title>
</head>
<body>
<h1>
<?php print $message ?>
</h1>
<form action="<?php print $PHP_SELF?>" method="POST">
  Type your guess here: <input type="text" name="guess">
</form>
</body>
</html>

The code above generates the following result.

Get text input value from a form in PHP




















Home »
  PHP Tutorial »
    Form »




PHP Form
Form Demo