A
Anonymous
Guest
I am using PHP version 4.2 with Apache 2, I wrote functions for getting
input in form.
I pasted the code below:
<html>
<head>
<body bgcolor="#FFFFFF" text="#000000">
<?
function error_flag($error, $field) {
if($error[$field]) {
print("<td class=error>");
} else {
print ("<td>");
}
}
function print_form() {
global $error , $print_again, $first, $last, $page;
?>
<form action="/phppractice/form1.php" method="post">
<?
if($print_again) {
?>
<h3>You missed some fields, Pleas correct the <span class=error>red</span> fields.
<?
}
else {
?>
<h3>Please fill-in the following fields.</h3>
<?
}
?>
<table border="0">
<tr><td <? error_flag($error, "first"); ?>First Name:</td>
<td><input type="text" name="first" value="<?=$first ?>"></td></tr>
<tr><td <? error_flag($error, "last"); ?>Last Name:</td>
<td><input type="text" name="last" value="<?=$last ?>"></td></tr>
<tr><td colspan="2" align="center">
<td><input type="submit" name="submit" value="Submit Form"></td></tr>
</table>
</form>
<?
}
function check_form() {
global $error, $print_again, $first, $last;
$error['first'] = false;
$error['last'] = false;
$print_again = false;
if($first == ""){
$error['first'] = true;
$print_again = true;
}
if($last == "") {
$error['last'] = true;
$print_again = true;
}
if ($print_again) {
print_form();
} else {
print("<h3>Thank you for completing the form!</h3>");
}
}
/****** MAIN *******/
$abc = isset($submit);
echo ($abc);
IF (isset($submit)) {
check_form();
} else {
print_form();
}
?>
</body>
</html>
The print_form() function is run again and again even if I
enter the value into first name and last name and
If anyone know please help me. Thanks in advance.
Regards
Muhammad ALi
input in form.
I pasted the code below:
<html>
<head>
<body bgcolor="#FFFFFF" text="#000000">
<?
function error_flag($error, $field) {
if($error[$field]) {
print("<td class=error>");
} else {
print ("<td>");
}
}
function print_form() {
global $error , $print_again, $first, $last, $page;
?>
<form action="/phppractice/form1.php" method="post">
<?
if($print_again) {
?>
<h3>You missed some fields, Pleas correct the <span class=error>red</span> fields.
<?
}
else {
?>
<h3>Please fill-in the following fields.</h3>
<?
}
?>
<table border="0">
<tr><td <? error_flag($error, "first"); ?>First Name:</td>
<td><input type="text" name="first" value="<?=$first ?>"></td></tr>
<tr><td <? error_flag($error, "last"); ?>Last Name:</td>
<td><input type="text" name="last" value="<?=$last ?>"></td></tr>
<tr><td colspan="2" align="center">
<td><input type="submit" name="submit" value="Submit Form"></td></tr>
</table>
</form>
<?
}
function check_form() {
global $error, $print_again, $first, $last;
$error['first'] = false;
$error['last'] = false;
$print_again = false;
if($first == ""){
$error['first'] = true;
$print_again = true;
}
if($last == "") {
$error['last'] = true;
$print_again = true;
}
if ($print_again) {
print_form();
} else {
print("<h3>Thank you for completing the form!</h3>");
}
}
/****** MAIN *******/
$abc = isset($submit);
echo ($abc);
IF (isset($submit)) {
check_form();
} else {
print_form();
}
?>
</body>
</html>
The print_form() function is run again and again even if I
enter the value into first name and last name and
If anyone know please help me. Thanks in advance.
Regards
Muhammad ALi