"undefined" space on 1st name/value pair URLLoaderDataFormat.VARIABLES

Hi, I hope this is an easy answer…it has me stumped now for half a day. The problem is simply my first variable is “undefined”, but everything else loads fine, I ran a trace(evt.target.data) and found that there is a space in front of my first return Name/Value Pair. However, there is nothing in my PHP code nor my AS3 code telling the data to add a space. I will post code below…hoping someone has chased down this rabbit trail before.

PHP:


//trying to save space on forum...up here I properly define my $string vars "First Name" is where the problem is.
include 'db_info.php';

$field0="First Name";
$field1="Last Name";
$field2="Company Name";
//skipping ahead...to save space
$field71="Notes";
$field72="Flagged";
$field73="Closed";
$field74="Encryption Key";

$connect = mysql_connect($db_server, $db_name, $db_pass);
mysql_select_db($db_name, $connect);

$result = mysql_query("SELECT `First Name`, `Last Name`, `Company Name`, `SSN`, `EIN`, `Address`, `City`, `State`, `Zip`, `Phone`, `Fax`, `Cell`, `Email`, `Website`, `Loan Number`, `Loan Amount`, `Generation Type`, `Generation Fee`, `Transaction Type`, `Interest Rate`, `Down Payment`, `Monthly Payment`, `Monthly Payment Due Date`, `Value`, `LTV`, `Origination Date`, `Start Date`, `Due Date`, `Paid Off Date`, `Payoff Amount`, `Status`, `Fee Amount`, `Fees Accrued`, `Fees Paid`, `PFS Split`, `Investor Split`, `Date Received`, `Check Number`, `Check Amount`, `Property Address`, `Property City`, `Property State`, `Property Zip`, `Property Type`, `Property Sq Ft`, `Property Year Built`, `Bedrooms`, `Bathrooms`, `Pool`, `Garage`, `Parking Spaces`, `Roof`, `Structure`, `Zoning`, `Investor First Name`, `Investor Last Name`, `Investor`, `Investor Company Name`, `Investor SSN`, `Investor EIN`, `Investor Address`, `Investor City`, `Investor State`, `Investor Zip`, `Investor Phone`, `Investor Fax`, `Investor Cell`, `Investor Email` , `Investor Website` , `Investment Amount` , `Investment Date` , `Notes` , `Flagged` , `Closed` , `Encryption Key` FROM `PFF_main_db` LIMIT 0 , 30");

$cant = 0;

while($row=mysql_fetch_array($result)){

     echo "$field0$cant=$row[$field0]&$field1$cant=$row[$field1]&$field2$cant=$row[$field2]&$field3$cant=$row[$field3]&$field4$cant=$row[$field4]&$field5$cant=$row[$field5]&$field6$cant=$row[$field6]&$field7$cant=$row[$field7]&$field8$cant=$row[$field8]&$field9$cant=$row[$field9]&$field10$cant=$row[$field10]&$field11$cant=$row[$field11]&$field12$cant=$row[$field12]&$field13$cant=$row[$field13]&$field14$cant=$row[$field14]&$field15$cant=$row[$field15]&$field16$cant=$row[$field16]&$field17$cant=$row[$field17]&$field18$cant=$row[$field18]&$field19$cant=$row[$field19]&$field20$cant=$row[$field20]&$field21$cant=$row[$field21]&$field22$cant=$row[$field22]&$field23$cant=$row[$field23]&$field24$cant=$row[$field24]&$field25$cant=$row[$field25]&$field26$cant=$row[$field26]&$field27$cant=$row[$field27]&$field28$cant=$row[$field28]&$field29$cant=$row[$field29]&$field30$cant=$row[$field30]&$field31$cant=$row[$field31]&$field32$cant=$row[$field32]&$field33$cant=$row[$field33]&$field34$cant=$row[$field34]&$field35$cant=$row[$field35]&$field36$cant=$row[$field36]&$field37$cant=$row[$field37]&$field38$cant=$row[$field38]&$field39$cant=$row[$field39]&$field40$cant=$row[$field40]&$field41$cant=$row[$field41]&$field42$cant=$row[$field42]&$field43$cant=$row[$field43]&$field44$cant=$row[$field44]&$field45$cant=$row[$field45]&$field46$cant=$row[$field46]&$field47$cant=$row[$field47]&$field48$cant=$row[$field48]&$field49$cant=$row[$field49]&$field50$cant=$row[$field50]&$field51$cant=$row[$field51]&$field52$cant=$row[$field52]&$field53$cant=$row[$field53]&$field54$cant=$row[$field54]&$field55$cant=$row[$field55]&$field56$cant=$row[$field56]&$field57$cant=$row[$field57]&$field58$cant=$row[$field58]&$field59$cant=$row[$field59]&$field60$cant=$row[$field60]&$field61$cant=$row[$field61]&$field62$cant=$row[$field62]&$field63$cant=$row[$field63]&$field64$cant=$row[$field64]&$field65$cant=$row[$field65]&$field66$cant=$row[$field66]&$field67$cant=$row[$field67]&$field68$cant=$row[$field68]&$field69$cant=$row[$field69]&$field70$cant=$row[$field70]&$field71$cant=$row[$field71]&$field72$cant=$row[$field72]&$field73$cant=$row[$field73]&$field74$cant=$row[$field74]&";

     $cant++;

}

echo "cant=$cant";
?>

AS3


LoadSQL(db_fields, "");

function LoadSQL(array:Array,str:String):void
		{
			var myLoader:URLLoader = new URLLoader()
			myLoader.dataFormat = URLLoaderDataFormat.VARIABLES

			myLoader.load(new URLRequest("test.php"))
			myLoader.addEventListener(Event.COMPLETE, onDataLoad)
			myLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError)
			myLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError)
			myLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHTTPStatus)    

			function onDataLoad(e:Event)
			{
				for(var i:uint=0; i<e.target.data.cant; i++)
				{	
					for(var a:Number = 0; a < db_fields.length; a++)
					{
						str+=e.target.data[array[a]+i];
					}
				}
                                trace(str);
                                trace(e.target.data);//see below
                      }
             }

Array For Reference:


public var db_fields:Array = new Array("First Name", "Last Name", "Company Name", "SSN", "EIN", "Address", "City", "State", "Zip", "Phone", "Fax", "Cell", "Email", "Website", "Loan Number", "Loan Amount", "Generation Type", "Generation Fee", "Transaction Type", "Interest Rate", "Down Payment", "Monthly Payment", "Monthly Payment Due Date", "Value", "LTV", "Origination Date", "Start Date", "Due Date", "Paid Off Date", "Payoff Amount", "Status", "Fee Amount", "Fees Accrued", "Fees Paid", "PFS Split", "Investor Split", "Date Received", "Check Number", "Check Amount", "Property Address", "Property City", "Property State", "Property Zip", "Property Type", "Property Sq Ft", "Property Year Built", "Bedrooms", "Bathrooms", "Pool", "Garage", "Parking Spaces", "Roof", "Structure", "Zoning", "Investor First Name", "Investor Last Name", "Investor", "Investor Company Name", "Investor SSN", "Investor EIN", "Investor Address", "Investor City", "Investor State", "Investor Zip", "Investor Phone", "Investor Fax", "Investor Cell", "Investor Email", "Investor Website", "Investment Amount", "Investment Date", "Notes", "Flagged", "Closed", "Encryption Key")

That should be all the code needed. I don’t see any errors in my code…is this a bug? or is there a better way to work around this? I read somewhere to use…URLLoaderDataFormat.TEXT but that would break up my name value pairs wouldn’t it. I need those. I also tried to do a e.target.data.replace(" First Name0", “First Name0”) but had no effect. Is there another way to talk to “data” if I could talk to it like an array. e.target.data[0] then I could just manually correct it.

Anyway here are outputs for traces above.

Check%20Amount0=Check%20Amount&PFS%20Split0=PFS%20Split&Investor0=Investor&Monthly%20Payment0=Monthly%20Payment&Investment%20Date0=Investment%20Date&Cell0=Cell&Address0=Address&Fees%20Paid0=Fees%20Paid&Last%20Name0=Last%20Name&Roof0=Roof&Phone0=Phone&Investor%20Company%20Name0=Investor%20Company%20Name&Down%20Payment0=Down%20Payment&Property%20Sq%20Ft0=Property%20Sq%20Ft&Payoff%20Amount0=Payoff%20Amount&Investor%20Phone0=Investor%20Phone&Generation%20Fee0=Generation%20Fee&Check%20Number0=Check%20Number&Parking%20Spaces0=Parking%20Spaces&Property%20Type0=Property%20Type&Website0=Website&Status0=Status&Investor%20SSN0=Investor%20SSN&Generation%20Type0=Generation%20Type&Origination%20Date0=Origination%20Date&Company%20Name0=Company%20Name&Zip0=Zip&Investor%20Fax0=Investor%20Fax&Investor%20Zip0=Investor%20Zip&Flagged0=Flagged&Garage0=Garage&Date%20Received0=Date%20Received&Property%20Zip0=Property%20Zip&State0=State&Start%20Date0=Start%20Date&Investor%20EIN0=Investor%20EIN&SSN0=SSN&Structure0=Structure&Investor%20Split0=Investor%20Split&Property%20State0=Property%20State&Monthly%20Payment%20Due%20Date0=Monthly%20Payment%20Due%20Date&Closed0=Closed&Pool0=Pool&Investor%20Cell0=Investor%20Cell&Fax0=Fax&Fees%20Accrued0=Fees%20Accrued&Zoning0=Zoning&Value0=Value&Investor%20Email0=Investor%20Email&Transaction%20Type0=Transaction%20Type&Investor%20Address0=Investor%20Address&Email0=Email&Encryption%20Key0=Encryption%20Key&EIN0=EIN&Fee%20Amount0=Fee%20Amount&Bathrooms0=Bathrooms&Paid%20Off%20Date0=Paid%20Off%20Date&Investor%20City0=Investor%20City&Interest%20Rate0=Interest%20Rate&Investor%20First%20Name0=Investor%20First%20Name&Property%20City0=Property%20City&Loan%20Number0=Loan%20Number&Investor%20Website0=Investor%20Website&cant=1&Notes0=Notes&Due%20Date0=Due%20Date&Property%20Address0=Property%20Address&Bedrooms0=Bedrooms&Loan%20Amount0=Loan%20Amount&***%20First%20Name0***=First%20Name&City0=City&LTV0=LTV&Investment%20Amount0=Investment%20Amount&Investor%20State0=Investor%20State&Property%20Year%20Built0=Property%20Year%20Built&Investor%20Last%20Name0=Investor%20Last%20Name

trace(str);
//again to save space…
undefinedLast NameCompany Name…//and so on, have to rows and second row “First Name1” name/value pair is just fine…only first variable gets a “space” for no reason.

I’m stumped…any ideas. Thanks!
Chad