append strings...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hc
Forum Newbie
Posts: 13
Joined: Wed Oct 25, 2006 2:00 pm

append strings...

Post 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;
	}
hc
Forum Newbie
Posts: 13
Joined: Wed Oct 25, 2006 2:00 pm

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

Post by hc »

I still can't figure out why my string $UserAdded is blank. Can anyone tell me why that might be?? Thanks

HC
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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 = '';
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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);
hc
Forum Newbie
Posts: 13
Joined: Wed Oct 25, 2006 2:00 pm

thanks folks

Post 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
Post Reply