Hi Folks
I'm having a problem with the program below , The Problem is that I want it to validate numbers between 0-100 , so I use the '/^[0-100]+$/' , So I call up the webpage , enter in in 75 , It doesn't work keeps throwing up the error "The Marks Must be Between 0 and 100" now here is the unusual bit , if I change the '/^[0-100]+$/' to '/^[0-50]+$/' and call up the page & enter 45 , the program runs fine, why will it not work with '/^[0-100]+$/'.
CODE
<?php
if (isset($_REQUEST['button']))
{
$error = validate_form();
if($error)
{
display_form_page($error);
}
else
{
display_output_page();
}
}
else
{
display_form_page('');
}
?>
<?php
function display_form_page($error)
{
$self = $_SERVER['PHP_SELF'];
$grade = isset($_REQUEST['sgrade']) ? $_REQUEST['sgrade'] : '';
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="input.css"/>
<title>STICKY MARKS</title>
<style type="text/css">
.error {color: #ff0000}
</style>
</head>
<body>
<h1>Sticky Marks</h1>
<?php
if ($error)
{
echo "<p>$error</p>\n";
}
?>
<form action="<?php echo $self ?>" method="post">
<p>Please Enter a mark (between 0 and 100);</p>
<p>MARK: <input class="input" type="text" name="sgrade"
value="<?php echo $grade?>"></p>
<p><input type="submit" name="button" value="Submit Name"></p>
</form>
</body>
</html>
<?php
}
?>
<?php
function validate_form()
{
$grade = trim($_REQUEST['sgrade']);
$error = '';
$regxp = '/^[0-100]+$/';
if (! preg_match($regxp,$grade))
{
$error .=
"<span class=\"error\">The Marks Must be Between 0 and 100</span><br>";
}
if($grade >= 100)
{
$error .=
"<span class=\"error\">You Must Enter a Number between 0 and 100</span><br>";
}
return $error;
}
?>
<?php
function display_output_page()
{
$grade = trim($_REQUEST['sgrade']);
?>
<html>
<head>
<title>Grade Result</title>
</head>
<body>
<?php
echo "A mark of $grade is given to you ";
?>
</body>
</html>
<?php
}
?>