I have a problem that I cannot for the life of me find a solution to and since I have received assistance on this forum before I thought I would give it a try here again.
I posted this question earlier but I did not have time to finish it before I had to leave for work. I will paste my code from two programs I am trying to run together to collect and manipulate data entered from a user. The first is an HTML file that is supposed to collect the data and send it to a PHP script to work with. This is the HTML code I have.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Words for Jumble</title>
</head>
<body>
<?php>
<h3>Please enter 4 words between 4 and 7 characters long</h3>
<form action="Jumble.php" method="post">
<p>word 1: <input type="text" name="word 1"></p>
<p>word 2: <input type="text" name="word 2"></p>
<p>word 3: <input type="text" name="word 3"</p>
<p>word 4: <input type="text" name="word 4"</p>
<input type="reset" value="Clear Form" />
<input type="submit" name="submit" value="send form" />
</form></?>
</body>
</html>
this is I believe working correctly except the data does not seem to be getting to the PHP script correctly. This is the PHP script that is supposed to get the data entered into the HTML page and manipulate it but it keeps failing at the if (empty($data)) condition which means the data is not being entered but I know that it is entered because I have entered the data every time I tested this but it is not being passed to the PHP file correctly somehow. Anyway here is the PHP script code and maybe you can see the issue I keep missing.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title>Word Jumble</title>
<body>
<?php
error_reporting(E_ALL & ~E_NOTICE);
function DisplayError($fieldName, $errorMsg) {
echo "Error for \ "$fieldName\": $errorMsg<br \>\n";
++$errorCount; }
function wordCheck($data, $fieldName) {
global $errorCount;
//this line fails// if (empty($data)) {
displayError($fieldName, "You must enter a word here between 4 and 7 chracters");
$retval = "";
else {
$retval = trim($data);
$retval = striplashes($retval);
if ((strlen(($retval)<4))|| (strlen($retval)>7)) {
displayError($fieldName, Must be between 4 ans 7 characters in length"); }
if (preg_match("/^[a-z]+$/i", $retval)==0){
displayError($fieldName, Words must be letters only");
}
}
$retval = strtoupper($retval);
$retval = str_shuffle($retval);
return($retval);
}
$words[] = wordCheck($_POST["word 1"], "word 1");
$words[] = wordCheck($_POST["word 2"], "word 2");
$words[] = wordCheck($_POST["word 3"], "word 3");
$words[] = wordCheck($_POST["word 4"], "word 4");
if ($errorCount>0)
echo "Please re-enter data.<br />\n";
else {
$wordnum = 0;
foreach ($words as $Word)
echo "Word ", ++$wordnum.": $Word<br />\n";
}
?>
</body>
</html>
This is the output I get no matter what I enter:
Error for "word 1": You must enter a word here between 4 and 7 characters
Error for "word 2": You must enter a word here between 4 and 7 characters
Error for "word 3": You must enter a word here between 4 and 7 characters
Error for "word 4": You must enter a word here between 4 and 7 characters
Word 1:
Word 2:
Word 3:
Word 4:
Please help me!! this project is due Friday and I cannot see what mistake I am making here. Thanks in advance for any assistance!!
Zack