Chapter 5
Hi
In the book I have "Beginning PHP4" I found an error in the section "Iterating through an array" THe code for the states.php errored when I tried it. I checked the code and then downloaded the code for the page from the Wrox site. Still the error occured. Ihave amended the code to work as follows:
<body>
<form action="capitals.php" method="post">
<p>What state do you want to know the capital of?
<?php
echo "<select name=State>";
$StatesOfTheUSA = array (1 => "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "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='$StatesOfTheUSA[$counter]'>";
}
?>
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
the code from the book, copied from the Wrox web site is:
<BODY>
<FORM ACTION="capitals.php" METHOD=POST>
What state do you want to know the capital of?
<SELECT NAME=State>
<?php
$StatesOfTheUSA = array (1 => "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "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='$StatesOfTheUSA[$counter]'>";
}
echo "<INPUT TYPE=SUBMIT></FORM>";
?>
</BODY>
I am a keen to learn PHP which is my first attempt at learning a programming language. My background is in the Printing Trade. Due to the advance in technologies over the years I found I needed to learn more and more about working with computer software. This next step into programming seems a natural progression.
Cheers
LApidos
|