Page 1 of 1

append strings...

Posted: Sun Oct 29, 2006 10:40 pm
by hc
Hey Guys, All I want to do here is append this string as it loops through and print out the following values

echo $sUserAdded;
echo $sTaxIDExists;
echo $sUsernameExists;

I know it gets in the loop, because I can print out the SQL statements...what simpleton thing am I doing wrong here... Thanks

Code: Select all

	case "officials":
	{
		echo 'Here we will do lookup by both tax_id and email. If either exists, we will skip the record, if not we will insert';
		echo '</br></br>';
		$user = new Employee();

		foreach ($_POST['chk'] as $name => $val)
		{
			$title = $_POST['title_' . $val];
			$fname = $_POST['fname_' . $val];
			$mname = $_POST['mname_' . $val];
			$lname = $_POST['lname_' . $val];
			$tax_id = $_POST['taxid_' . $val];
			$username = $_POST['username_' . $val];
			$password = $_POST['password_' . $val];
			$suffix = $_POST['suffix_' . $val];

			if(isset($tax_id))
			{
				$sqlstrGetByTaxID = <<< SQL
					SELECT
						id
					FROM
						users.employees
					WHERE
						tax_id = '$tax_id'
SQL;

				$sqlstrGetByUsername = <<< SQL
					SELECT
						id
					FROM
						users.employees
					WHERE
						username = '$username'
SQL;

				if($db->query($sqlstrGetByTaxID))
				{
					while($row = $db->fetch())
					{
						$sTaxIDExists .= 'User Tax ID' . '-' . $tax_id . '</br>';
					}
				}
				elseif($db->query($sqlstrGetByUsername))
				{
					while($row = $db->fetch())
					{
						$sUsernameExists .= 'Username Exists' . '-' . $username . '</br>';
					}
				}

				else
				{
					$sUserAdded .= 'User Added' . '-' . $tax_id . '</br>';
				}
				echo $sUserAdded;
				echo $sTaxIDExists;
				echo $sUsernameExists;
			}

		}
		break;
	}

ok, so it looks like I am parsing the string right, but...

Posted: Sun Oct 29, 2006 11:23 pm
by hc
I still can't figure out why my string $UserAdded is blank. Can anyone tell me why that might be?? Thanks

HC

Posted: Sun Oct 29, 2006 11:45 pm
by John Cartwright
Add some debugging echo()'s and var_dump()'s in all your if / else if / else statements to see what the code values are producing. You may not be getting some expected returns on some of your method calls or something.

Also, try initializing the string first, so before the loop add

Code: Select all

$sUserAdded = '';

Posted: Mon Oct 30, 2006 1:07 am
by n00b Saibot
Check your error logs. I suppose there will be some error messages about variable $sUserAdded not being declared etc.
always try to develop/debug having following line at the start :arrow:

Code: Select all

error_reporting(E_ALL);

thanks folks

Posted: Mon Oct 30, 2006 9:06 am
by hc
the problem was pretty simple, the code was making it into my for loop, and into the first if condition, but never into the while condition. So consequently, the else condition was never getting hit...pretty dumb of me actually. Thanks alot