p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: chp 5 page 168


Message #1 by "Josh" <jeb_braun@i...> on Tue, 30 Apr 2002 06:26:53
OK i'm on chp 5(loops & arrays) page 168 and can't get this example to 
work. Its probaly something simple, but if it is I can't see the problem. 
I getting this error
Parse error: parse error, expecting `')'' in 
C:\Inetpub\wwwroot\learning\states2.php on line 7

Here is the first page which works fine

States.php

<html>
<head>
<title>Guess Capital</title>
</head>
<body>
<FORM ACTION="states2.php" METHOD=POST>
What state do you what to know the capital of?
<SELECT NAME=State>
<?php

$StatesOfTheUSA = array (1 
=> "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "C
onnecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinios
", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland
", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Mo
ntana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New 
Mexico", "New York", "North Carolina", "North 
Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rode 
Island", "South Caolina", "South 
Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington",
 "West Virginia", "Wisconsin", "Wyoming");
for ($counter=1; $counter<51; $counter++) {
	echo "<OPTION>$StatesOfTheUSA[$counter]</OPTION>";
}
echo "</SELECT><BR><BR>";
for ($counter=1; $counter<51; $counter++) {
	echo "<INPUT TYPE=HIDDEN NAME='HiddenState[]' VALUE='$StateOfUSA
[$counter]'>";
}
echo "<INPUT TYPE=Submit></SELECT>";
?>
</FORM>
</body>
</html>


Here is the second page

States2.php

<html>
<head>
<title>Guess Capital</title>
</head>
<body>
<?php
$StateCapital = array (0 => "Montgomery", "Juneau", "Phoenix", "Little 
Rock", "Sarcamento", "Denver", 
Hartford", "Dover", "Tallahasse", "Atlanta", "Honolulu", "Boise", "Springfi
eld", "Indianapolis", "Des Moines", "Topeka", "Frankfort", "Baton 
Rouge", "Augusta", "Annapolis", "Boston", "Lansing", "Saint 
Paul", "Jackson", "Jefferson City", "Helena", "Lincoln", "Carson 
City", "Concord", "Trenton", "Santa 
Fe", "Albany", "Raleigh", "Bismarck", "Columbus", "Oklahoma 
City", "Salem", "Harrisburg", "Providence", "Columbia", "Pierre", "Nashvill
e", "Austin", "Salt Lake 
City", "Montpelier", "Richmond", "Olympia", "Charleston", "Madison", "Cheye
nne") ;
for ($counter=0; $counter<50; $counter++)
{
	if ($HiddenState[$counter]==$State)
	{
		echo "The State capital is $StateCapital[$counter]";
	}
}
?>
</body>
</html>

And I probaly spelled some names wrong but I'm a horible speller. Thanks

  Return to Index