I have a registration page I am creating which passes Ajax data from a form to the function ProcessSignUpData. I am trying to use ucwords on this function for the name, address and city form fields and it isn't working. Any Suggestions what be greatly appreciated! If I am not providing enough information, please let me know!

Here is what the code looks like:

if ($_POST['ProcessSignUpData'])
{
	usleep(3500000);
	unset($Data);
	$Data['OldCardNbr'] = substr(preg_replace("/[^0-9]*/", "", $_POST['SavingsClub']), -8);
	$Data['FName'] = ucwords($_POST['FirstName']);
	$Data['LName'] = ucwords($_POST['LastName']);
	$Data['Address1'] = ucwords($_POST['Address1']);
	$Data['Address2'] = ucwords($_POST['Address2']);
	$Data['City'] = ucwords($_POST['City']);
	$Data['State'] = $_POST['State'];
	$Data['Zip'] = preg_replace("/[^0-9]*/", "", $_POST['ZipCode']);
	if (ValidateEMail($_POST['EMail'])) $Data['EmailAddr'] = $_POST['EMail'];
	$Data['HPhone'] = phone_format($_POST['HomePhone']);
	$Data['WPhone'] = phone_format($_POST['MobilePhone']);
	$Data['BirthYear'] = preg_replace("/[^0-9]*/", "", $_POST['BirthYear']);
	$Data['BirthMo'] = preg_replace("/[^0-9]*/", "", $_POST['BirthMonth']);
	$Data['Sex'] = preg_replace("/[^MF]*/", "", $_POST['Gender']);
	$NumberOfCards = preg_replace("/[^0-9]*/", "", $_POST['NumberOfCards']);

if ($Data['FName'] && $Data['LName'] && $Data['Address1'] && $Data['City'] && $Data['Zip'])
{
	// Check to see if the person is already signed up with a new card number (dupliate signup check)
	$IsDup = FALSE;

	// First check database SCVL1
	$My->query("select `MembNbr`, `HPhone`, `EmailAddr`, `OldCardNbr` from `member` where `FName` = '" . $My->escape($Data['FName']) . "' and `LName` = '" . $My->escape($Data['LName']) . "' and `State` = '" . $My->escape($Data['State']) . "' and substr(`Zip`, 1, 5) = '" . $My->escape(substr($Data['Zip'], 0, 5)) . "'");
	if ($DupCheck = $My->fetchArray())
	{
		do
		{
			if (substr($DupCheck['MembNbr'], 0, 1) == "6")
			{
				$IsDup = TRUE;
				if ($Data['EmailAddr'] && $DupCheck['EmailAddr'])
				{
					if ($Data['EmailAddr'] != $DupCheck['EmailAddr'])
					{
						$IsDup = FALSE;
					}
				}
				if ($Data['HPhone'] && $DupCheck['HPhone'])
				{
					if ($Data['HPhone'] != $DupCheck['HPhone'])
					{
						$IsDup = FALSE;
					}
				}
			}
			if ($IsDup === TRUE) break;
		}
		while ($DupCheck = $My->fetchArray());
	}

	// Then check database SCVL3 if no dup found in SCVL1
	if ($IsDup === FALSE)
	{
		$My3->query("select `MembNbr`, `HPhone`, `EmailAddr`, `OldCardNbr` from `tblmember` where `FName` = '" . $My->escape($Data['FName']) . "' and `LName` = '" . $My->escape($Data['LName']) . "' and `State` = '" . $My->escape($Data['State']) . "' and substr(`Zip`, 1, 5) = '" . $My->escape(substr($Data['Zip'], 0, 5)) . "'");
		if ($DupCheck = $My3->fetchArray())
		{
			do
			{
				if (substr($DupCheck['MembNbr'], 0, 1) == "6")
				{
					$IsDup = TRUE;
					if ($Data['EmailAddr'] && $DupCheck['EmailAddr'])
					{
						if ($Data['EmailAddr'] != $DupCheck['EmailAddr'])
						{
							$IsDup = FALSE;
						}
					}
					if ($Data['HPhone'] && $DupCheck['HPhone'])
					{
						if ($Data['HPhone'] != $DupCheck['HPhone'])
						{
							$IsDup = FALSE;
						}
					}
				}
				if ($IsDup === TRUE) break;
			}
			while ($DupCheck = $My3->fetchArray());
		}
	}

	// Show an error if a dup was found
	if ($IsDup === TRUE)
	{

    Can you do a [man]var_dump/man on both $_POST['FirstName'] and $Data['FName'] (or any other pair which doesn't seem to be working) and show us the output?

      Thanks for the reply but I found a fix that seems to work.

      For some reason it works when I add 'strtolower' which I realized I needed anyway to make the remaining characters lowercase. I tested it out and it hit the database correctly!

      Crazy! Here is the new example:

      $Data['FName'] = ucwords(strtolower($_POST['FirstName']));
      $Data['LName'] = ucwords(strtolower($_POST['LastName']));
      $Data['Address1'] = ucwords(strtolower($_POST['Address1']));
      $Data['Address2'] = ucwords(strtolower($_POST['Address2']));
      
        Write a Reply...