Hi All,
I am learning to validate a simple form with a single entry.
I am using $_GET in the input and using PHP_SELF to test for form being submitted, then displaying an error if the user enters invalid information.
It works find uploaded to the web, but fails locally.
I'm using WIndows XP and PHP 4.3.3
Hope someone can help.
TIA - Dave Porter
PHP Code:
<?php # Script 4.1 simple version djp
if (isset($_POST['submit'])) { // If the form was submitted, process it.
// Check the username.
if (eregi ("^[[:alnum:]]+$", $_POST['username'])) {
$a = TRUE;
} else {
$a = FALSE;
$message[] = "Please enter a username that consists only of letters and numbers.";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"[url=http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd]http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd[/url]">
<html xmlns="[url=http://www.w3.org/1999/xhtml]http://www.w3.org/1999/xhtml[/url]">
<head>
<title>Register</title>
</head>
<body>
<?php
// Print out any error messages.
if ($message) {
echo "<div align=\"left\"><font color=red><b>The following problems occurred:</b><br />\n";
foreach ($message as $key => $value) {
echo "$value <br />\n";
}
}
?>
<?php # daves test
echo "<p>test</p>";
if (isset($_POST['submit'])) {
echo "<p>submit 1</p>";
} else {
echo "<p>submit 2</p>";
}
echo ('<p>test ' . $_POST['username'] . '</p>');
?>
<!-- hello -->
<!-- <form action="regsimp.php" method="post"> -->
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0" width="90%" cellspacing="2" cellpadding="2" align="center">
<tr>
<td align="right">Username</td>
<td align="left"><input type="text" name="username" value="<?php echo $_GET['username']; ?>" size="25" maxsize="16" </td>
<td align="left"><small>Maximum of 16 characters, stick to letters and numbers, no spaces, underscores, hyphens, etc.</small></td>
</tr>
<tr>
<td align="center" colspan="3"><input type="submit" name="submit" value="submit"> <input type="reset" name="Reset" value="Reset"></td>
</tr>
</table>
</form>
</body>
</html>
Bookmarks