0

I am trying to finish a project and have hit a snag and since I got helpful advice in this forum before I thought I give it another try. I am trying to make an html page that collects personal data and sends it to a php file that should store the data and show it on the screen.Unfortunately although the html file is calling the php file there is no data being sent between the two files. This is my code from the two files:

<!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>
<h3>Please enter personal information</h3>
<form action="Directory.php" method="post">
<p>Lastname: <input type="text" name="lastname"></p>
<p>Firstname: <input type="text" name="firstname"></p>
<p>Address: <input type="text" name="address"</p>
<p>City: <input type="text" name="city"</p>
<p>State: <input type="text" name="state"></p>
<p>Zipcode: <input type="text" name="zipcode"></p>
<p>Areacode: <input type="text" name="areacode"></p>
<p>Telephone: <input type="text" name="telephone"></p>
<input type="reset" value="Clear Form" />&nbsp;
&nbsp;<input type="submit" name="submit" value="send form" />
</form>
</body>
</html>

That is the html file which does open a web page with field labeled to enter information but it does not seem to be sending anything:icon_sad: to this php file:

<!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>Directory</title>
<body>
<b>Account Information:</b>
<?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;
		 if (empty($data)) {
		 	displayError($fieldName, "Please enter $fieldName");
			$retval = "";}
		  else {		  				  
		    if (preg_match("/^[a-z]+$/i", $retval)==0){
				displayError($fieldName, "Words must be letters only");
			}
		 	return($retval);
			}
			$words[] = wordCheck($_POST["lastname"], "lastname");
			$words[] = wordCheck($_POST["forstname"], "firstname");
			$words[] = wordCheck($_POST["address"], "address");
			$words[] = wordCheck($_POST["city"], "city");
			$words[] = wordCheck($_POST["state"], "state");
			$words[] = wordCheck($_POST["zipcode"], "zipcode");
			$words[] = wordCheck($_POST["areacode"], "areacode");
            $words[] = wordCheck($_POST["telephone"], "telephone");		
			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 does not even give error messages if you enter nothing in the html fields so I don't think the two files are sharing entered data at all!!:icon_cry:
Any assistance would be appreciated greatly as I am fairly new to server side scripting and do not have the familiarity with php to see what mistake or mistakes I have made here. I will await any helpful advice and thanks!!:icon_smile:

4
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by Dragonbaki
0

It looks like you are not closing your second function properly.

function wordCheck($data, $fieldName) {
	global $errorCount;
	if (empty($data)) 
	{
		displayError($fieldName, "Please enter $fieldName");
		$retval = "";
	} else {		  				  
		if (preg_match("/^[a-z]+$/i", $retval)==0)
		{
			displayError($fieldName, "Words must be letters only");
		}
		return($retval);
	}
} // <======= Missing this closing Bracket
$words[] = wordCheck($_POST["lastname"], "lastname");
$words[] = wordCheck($_POST["forstname"], "firstname");
$words[] = wordCheck($_POST["address"], "address");

It appears that you put the closing bracket for the function all the way at the end of the code. Make sure you remove one of the closing brackets at the end of the code.

$wordnum = 0;
	foreach ($words as $Word)
	echo "Word ", ++$wordnum.": $Word<br />\n";
	     }  } //<==== Remove one of these

Look into using an editor like Dreamweaver or Netbeans as they will help identify and highlight errors like these and maintain correctly indented code. When first starting out it is very difficult to spot errors, like this, if you don't adopt and maintain proper indentation. Actually, it is always difficult to follow improperly indented code.

0
function wordCheck($data, $fieldName)
  {
  global $errorCount;
  if (empty($data))
    {
    displayError($fieldName, "Please enter $fieldName");
    $retval = "";
    }
  else
    {
    if (preg_match("/^[a-z]+$/i", $retval)==0)
      {
      displayError($fieldName, "Words must be letters only");
      }
    return($retval);
    }

As above, you aren't closing your function, also noticed that $retval is set to "" if $data is empty, but not set to anything if $data is not empty. Unless I'm missing something wordCheck will always return either an empty string or a null value.

0

It looks like you are not closing your second function properly.

function wordCheck($data, $fieldName) {
	global $errorCount;
	if (empty($data)) 
	{
		displayError($fieldName, "Please enter $fieldName");
		$retval = "";
	} else {		  				  
		if (preg_match("/^[a-z]+$/i", $retval)==0)
		{
			displayError($fieldName, "Words must be letters only");
		}
		return($retval);
	}
} // <======= Missing this closing Bracket
$words[] = wordCheck($_POST["lastname"], "lastname");
$words[] = wordCheck($_POST["forstname"], "firstname");
$words[] = wordCheck($_POST["address"], "address");

It appears that you put the closing bracket for the function all the way at the end of the code. Make sure you remove one of the closing brackets at the end of the code.

$wordnum = 0;
	foreach ($words as $Word)
	echo "Word ", ++$wordnum.": $Word<br />\n";
	     }  } //<==== Remove one of these

Look into using an editor like Dreamweaver or Netbeans as they will help identify and highlight errors like these and maintain correctly indented code. When first starting out it is very difficult to spot errors, like this, if you don't adopt and maintain proper indentation. Actually, it is always difficult to follow improperly indented code.

svilla,
First thanks for the reply:icon_biggrin: and I did make the changes you suggested but kept getting new ignorant errors and incorrect output.:icon_sad: The code I finally changed it to was as follows:

<!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>Directory</title>
<body>
<b>Account Information:</b>
<?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;
		 if (empty($data)) {
		 	displayError($fieldName, "Please enter $fieldName");
			$retval = "";}
		  else {		  				  
		    return($retval);
			}}
			$words[] = wordCheck($_POST["lastname"], "lastname");
			$words[] = wordCheck($_POST["firstname"], "firstname");
			$words[] = wordCheck($_POST["address"], "address");
			$words[] = wordCheck($_POST["city"], "city");
			$words[] = wordCheck($_POST["state"], "state");
			$words[] = wordCheck($_POST["zipcode"], "zipcode");
			$words[] = wordCheck($_POST["areacode"], "areacode");
            $words[] = wordCheck($_POST["telephone"], "telephone");		
			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>

but now when I run this script the output I get is this junk:
Account Information: Word 1:
Word 2:
Word 3:
Word 4:
Word 5:
Word 6:
Word 7:
Word 8:
so there is still nothing being passed between the programs and I don't know why the first field "Word 1:" is being placed beside the Account Information string!!:icon_evil: As I said I am fairly new to php and this is all confusing me to death!!:icon_mad: Do you see what else is wrong here??
Zack

0
function wordCheck($data, $fieldName)
  {
  global $errorCount;
  if (empty($data))
    {
    displayError($fieldName, "Please enter $fieldName");
    $retval = "";
    }
  else
    {
    if (preg_match("/^[a-z]+$/i", $retval)==0)
      {
      displayError($fieldName, "Words must be letters only");
      }
    return($retval);
    }

As above, you aren't closing your function, also noticed that $retval is set to "" if $data is empty, but not set to anything if $data is not empty. Unless I'm missing something wordCheck will always return either an empty string or a null value.

dietdew12z,
Thanks for the reply but I removed the second part of that condition altogether and it is still not working correctly:icon_sad:!! Now it is giving me nothing at all!!:icon_mad:!! For the record what I removed was

if (preg_match("/^[a-z]+$/i", $retval)==0)
      {
      displayError($fieldName, "Words must be letters only");
      }

because when I was running it I kept getting the errors that words must be letters only and nothing would print in the fields but when I take out that line all I get is 7 empty fields:icon_question: as in
Account Information: Word 1:
Word 2:
Word 3:
Word 4:
Word 5:
Word 6:
Word 7:
Word 8:
which is still FAIL!! Do you know what is going on please??:icon_cry:

0

Dont worry.. Now use this.. It works fine...

<!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>Directory</title>
<body>
<b>Account Information:</b>
<?php 
   error_reporting(E_ALL & ~E_NOTICE);
   $lname=$_POST["lastname"];
   $fname=$_POST["firstname"];
   $addr=$_POST["address"];
   $cty=$_POST["city"];
   $stat=$_POST["state"];
   $zip=$_POST["zipcode"];
   $acode=$_POST["areacode"];
   $phone=$_POST["telephone"];
   	$words[] = wordCheck($lname, "lastname");
	$words[] = wordCheck($fname, "firstname");
	$words[] = wordCheck($addr, "address");
	$words[] = wordCheck($cty, "city");
	$words[] = wordCheck($stat, "state");
    $words[] = wordCheck($zip, "zipcode");
    $words[] = wordCheck($acode, "areacode");
    $words[] = wordCheck($phone, "telephone");		
	
global $errorCount;
   function DisplayError($fieldName, $errorMsg) 
   {
   	echo "Error for \"$fieldName\": $errorMsg<br \>\n";
	++$errorCount;  
	}
	function wordCheck($data, $fieldName) 
	{
			
		 if (empty($data)) 
		 {
		 	DisplayError($fieldName, "Please enter $fieldName");
			$retval = "";
		}
		else 
		{	
			return $data;
		}
	}
				
	if ($errorCount>0)
	{
	echo "Please re-enter data.<br />\n";
	}
	else 
	{
				$wordnum = 0;
				foreach ($words as $Word)
				   echo "<br>Word ", ++$wordnum.": $Word";
	}   
?>
</body> 
</html>

Problem is, at line 18, the return value is wrong.
Hope you got it., If any probs, pls let me know...

0

Dont worry.. Now use this.. It works fine...

<!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>Directory</title>
<body>
<b>Account Information:</b>
<?php 
   error_reporting(E_ALL & ~E_NOTICE);
   $lname=$_POST["lastname"];
   $fname=$_POST["firstname"];
   $addr=$_POST["address"];
   $cty=$_POST["city"];
   $stat=$_POST["state"];
   $zip=$_POST["zipcode"];
   $acode=$_POST["areacode"];
   $phone=$_POST["telephone"];
   	$words[] = wordCheck($lname, "lastname");
	$words[] = wordCheck($fname, "firstname");
	$words[] = wordCheck($addr, "address");
	$words[] = wordCheck($cty, "city");
	$words[] = wordCheck($stat, "state");
    $words[] = wordCheck($zip, "zipcode");
    $words[] = wordCheck($acode, "areacode");
    $words[] = wordCheck($phone, "telephone");		
	
global $errorCount;
   function DisplayError($fieldName, $errorMsg) 
   {
   	echo "Error for \"$fieldName\": $errorMsg<br \>\n";
	++$errorCount;  
	}
	function wordCheck($data, $fieldName) 
	{
			
		 if (empty($data)) 
		 {
		 	DisplayError($fieldName, "Please enter $fieldName");
			$retval = "";
		}
		else 
		{	
			return $data;
		}
	}
				
	if ($errorCount>0)
	{
	echo "Please re-enter data.<br />\n";
	}
	else 
	{
				$wordnum = 0;
				foreach ($words as $Word)
				   echo "<br>Word ", ++$wordnum.": $Word";
	}   
?>
</body> 
</html>

Problem is, at line 18, the return value is wrong.
Hope you got it., If any probs, pls let me know...

Dragonbaki,
THANK YOU A MILLION TIMES OVER!!:icon_cheesygrin:
You are a lifesaver and it does work now!!!!:icon_smile:
Zack

0

Hey Zack.. These are all very huge words for me.. Thanks a lot... If any probs means, dont worry.. I am always here....

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.