הבעייה היא כי שכחת }
באמת, אני לא רוצה להעליב, אבל כדאי לך לעדכן את הידע שלך ב-HTML.
בכ"מ, תיקנתי לך את הכל.
PHP קוד:
<?php
$to_print = null;
$errors = array();
if (isset($_REQUEST["seen_already"])) {
validate_data();
if (count($errors) != 0) {
display_errors();
display_welcome();
} else {
process_data();
}
} else {
display_welcome();
}
function validate_data()
{
global $errors;
if ($_REQUEST["Name"] == "") {
$errors[] = "<span style='color:red;'>Please enter your name</span>";
}
if (strcmp($_REQUEST["Number"], strval(intval($_REQUEST["Number"])))) {
$errors[] = "<span style='color:red;'>Please enter an integer</span>";
}
}
function display_errors()
{
global $errors;
foreach ($errors as $err) {
$to_print.= $err. "<br />";
}
foreach ($errors as $err) {
$to_print.= $err. "<br />";
}
}
function process_data()
{
global $to_print;
$to_print.= "Your name is ";
$ok_text = htmlentities ($_REQUEST["Name"]);
$to_print.= $ok_text;
$to_print.= "Your integer is ";
$to_print.= $_REQUEST["Number"];
}
function display_welcome()
{
global $to_print;
$to_print.= <<<EOF
<form method='POST' action='index.php'>
What's your name?
<br />
<input type="text" name='Name'>
<br />
<br />
<input type="submit" VALUE="Submit">
<input type="hidden" name='seen_already' value='hidden_data'>
</form>
<form method='POST' action='index.php'>
Please enter an integer.
<br />
<input type="text" name='Number'>
<br />
<br />
<input type="hidden" name='seen_already' value='hidden_data'>
<input type="submit" VALUE="Submit">
</FORM>
EOF;
}
echo $to_print;
?>