I'm triyng to validate form fields from user input. The code works (somewhat) meaning i get no errors but it seems to only validate the last field as opposed to stopping on the the field that an error is found. I'm kinda new to php with a little asp. my test code is as follows:
<?
if ($submit == submit) {
$field = array("test", "test1", "test2" ,"test3", "test4", "test5"
for ($i = 0; $i < count($field); $i++) {
if (!preg_match("/^[a-zA-Z0-9]+$/",${$field[$i]})) {
} else {
if (${$field[$i]} = true) {
$msg = "good";
} else {
$msg ="not good";
}
}
}
}
?>
<form method=post action="test.php">
<p> <? echo "$msg"; ?>
<p> input test: <input type=text name="test" size=25>
<p> input test: <input type=text name="test1" size=25>
<p> input test: <input type=text name="test2" size=25>
<p> input test: <input type=text name="test3" size=25>
<p> input test: <input type=text name="test4" size=25>
<p> input test: <input type=text name="test5" size=25>
<p><input type=submit name="submit" value=submit>
</form>
<?
if ($submit == submit) {
$field = array("test", "test1", "test2" ,"test3", "test4", "test5"
for ($i = 0; $i < count($field); $i++) {
if (!preg_match("/^[a-zA-Z0-9]+$/",${$field[$i]})) {
} else {
if (${$field[$i]} = true) {
$msg = "good";
} else {
$msg ="not good";
}
}
}
}
?>
<form method=post action="test.php">
<p> <? echo "$msg"; ?>
<p> input test: <input type=text name="test" size=25>
<p> input test: <input type=text name="test1" size=25>
<p> input test: <input type=text name="test2" size=25>
<p> input test: <input type=text name="test3" size=25>
<p> input test: <input type=text name="test4" size=25>
<p> input test: <input type=text name="test5" size=25>
<p><input type=submit name="submit" value=submit>
</form>