Page 1 of 1

infinate loops

Posted: Fri Aug 11, 2006 4:23 pm
by Obadiah
ok guys im at stage 2: registration of my login and i left out one line of code...its a option box where the user can scroll down to select their state and it works as follows
(side note....this is a seperate file i called functions.php)

Code: Select all

<?php
function getStateCode()
{
	$stateCode = array(1=> "AL",
		"AK",
		"AZ",
		"AR",
		"CA",
		"CO",
		"CT",
		"DE",
                                "...",		
		"WY");
	return $stateCode;
}
function getStateName()
{
	$stateName = array(1=> "Alabama",
		"ALASKA",
		"ARIZONA",
		"ARKANSAS",
		"CALIFORNIA",
		"COLORADO",
		"CONNECTICUT",
		"DELAWARE",
                                "...",
		"WYOMING");
	return $stateName;
}
?>
pretty clever i thought bc it stores the state code in the database instead of the name....anyways getting to the point heres where i think i make a mess of things

in another file i put

Code: Select all

if($field == "state")
	{
		echo "<tr><td style=\"text-align:right;
				font-weight:bold\">State</td>
				<td><select name='state'>";
		$stateName=getStateName();
		$stateCode=getStateCode();
		for ($n=1;n<=50;$n++)
		{
			$state=$stateName[$n];
			$scode=$stateCode[$n];
			echo "<option value='$scode'";
			if($scode== @$_POST['state'])
				echo " selected";
			echo ">$state\n";
		}
	echo "</select>";
	}
to actually populate(i guess) the information

and here is the array for my form

Code: Select all

$fields_2 = 	array(	"user_name"	=> "User Name",
			"password"	=> "Password",
			"email"		=> "Email Address",
			"first_name"	=> "First Name",
			"last_name"	=> "Last Name",
			"street"	=> "Street",
			"city"		=> "City",
			"state"		=> "State",
			"zip"		=> "Zip",
			"phone"		=> "Phone",
			"Fax"		=> "Fax",
			);
here is the kicker....if i take out

Code: Select all

"state"		=> "State",
the form will run fine but it wont show my option box....but if i leave it in there the page takes forever to load and halfway through loading the page stops responding(infinate loop) did i forget to close or forget to add something that may be contributing to the problem?

Posted: Fri Aug 11, 2006 4:46 pm
by feyd
nothing in the code posted would create an infinite loop that I can see. ..but I also don't know how $fields_2 gets to your if posted above it.

Posted: Fri Aug 11, 2006 6:48 pm
by pureDesi

Code: Select all

for ($n=1;n<=50;$n++)
to

Code: Select all

for ($n=1;$n<=50;$n++)
forgot the $ in the second parameter of "for".
i do that all the time ><

Posted: Fri Aug 11, 2006 7:58 pm
by feyd
nice catch pureDesi, that one went right past me.

Image

Posted: Fri Aug 11, 2006 8:05 pm
by pureDesi
thanks, i do what i can :D