Quote
Immediatly after the validateWord() function, declare and initialize a new variable called $errorCount and a new array called $words[].
here is the code can you tell me if I inserted this variable in the correct position? the last (if)statement doesnt work.
<?php
function displayError($fieldName, $errorMsg) {
global $errorCount;
echo "Error for \"$fieldName\": $errorMsg<br />\n";
==$errorCount;
}
function validateWord($data, $fieldName) {
global $errorCount;
if (empty($data)) {
displayError($fieldName, "This field is
required");
$retval = "";
} else { //Only clean up the input if it isn't
//empty
$retval = trim(data);
$retval = stripslashes($retval);
if ((strlen($retval)<4) ||
(strlen($retval >7)) {
displayError($fieldName, "Words must be
at least four and at most
seven letters:);
}
}
$retval = strtoupper($retval);
$retval = str_shuffle($retval);
return($retval);
}
$errorCount = 0;
$words = array();
$words[] = validateWord($_POST['Word1'], "Word 1");
$words[] = validateWord($_POST['Word2'], "Word 2");
$words[] = validateWord($_POST['Word3'], "Word 3");
$words[] = validateWord($_POST['Word4'], "Word 4");
if ($errorCount>0)
echo "Please use the \"Back\" button to
re-enter the data.<br />\n";
else {
$wordnub = 0;
foreach ($words as $word)
echo "word ".++$wordnum.": $word<br />\n";
}
?>
Edited by Alexander, 28 November 2010 - 02:48 PM.
bbcode formatting


Sign In
Create Account


Back to top









