<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php
/*
* if the "submit" variable does not exist,
* the form has not been submitted - display initial page
*/
if(!isset($_POST['submit'])){
?>
<form action="
<?php echo $_SERVER['SCRIPT_NAME']; ?>"
method="post">Print all the squares between 1 and
<input type="text" name="limit" size="4" maxlength="4">
<input type="submit" name="submit" value="Go">
</form>
<?php
}
else{
/*
* if the "submit" variable exists,
* the form has been submitted - look for and process form data
*/
// set variables from form input
$upperLimit = $_POST['limit'];
$lowerLimit = 1;
// keep printing squares until lower limit = upper limit
while ($lowerLimit <= $upperLimit) {
echo ($lowerLimit * $lowerLimit).' ';
$lowerLimit++;
}
// print end marker
echo 'END';
}
?>
<!--
Use $_SERVER['SCRIPT_NAME'] instead of $_SERVER['PHP_SELF'].
because
$_SERVER['PHP_SELF'] will contain not just login.php, but the entire login.php/nearly_arbitrary_string.
-->
</body>
</html>
No comments:
Post a Comment