• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Debug my PHP script

nickmahon

New Member
I'm learning PHP right now, but this one has me stumped.

provinces.php:
Code:
<form method="post" action="provinces2.php">
Select a province to learn a city in it.
<select name="theprovinces">
<?php
$provinces = array(
	1=> "Newfoundland and Labrador",
	"Nova Scotia",
	"New Brunswick",
	"Prince Edward Island",
	"Quebec",
	"Ontario",
	"Manitoba",
	"Saskatchewan",
	"Alberta",
	"British Columbia",
	"Nunavut",
	"Northwest Territories",
	"Yukon Territory"
);
for($counter=1; $counter<14; $counter++) {
	print("<option>$provinces[$counter]</option>\n");
}
print("</select>\n");
for($counter=1; $counter<14; $counter++) {
	echo("<INPUT TYPE=HIDDEN NAME='hiddenprovince[]' VALUE='$provinces[$counter]'>\n");
}
?>
<br>
<input type="submit">
</form>

provinces2.php
Code:
<?php

$cities = array(
	0=> "Uhhhh...",
	"Halifax",
	"St. Johns",
	"Charlottetown",
	"Montreal",
	"Toronto",
	"Winnepeg",
	"Regina",
	"Calgary",
	"Vancouver",
	"Iqualit",
	"Yellowknife",
	"Whitehorse"
);

for ($counter=0; $counter<13; $counter++)
{
   if($hiddenprovince[$counter]==$theprovince)
   {
      echo"The State capital is $cities[$counter]";
   }
}

?>

It's basically supposed to be a dropdown menu, you select a province, press go, and it displays a city in that province... but instead it displays a blank page. :confused2
 
I think this will give you what you want...you should be able to select different cities in each province though, cause there is usually more than one.
provinces.php

PHP:
<form method="post" action="provinces2.php">
Select a province to learn a city in it.
<select name="theprovinces">
<?php
$provinces = array(
	0=> "Newfoundland and Labrador",
	"Nova Scotia",
	"New Brunswick",
	"Prince Edward Island",
	"Quebec",
	"Ontario",
	"Manitoba",
	"Saskatchewan",
	"Alberta",
	"British Columbia",
	"Nunavut",
	"Northwest Territories",
	"Yukon Territory"
);
for($counter=0; $counter<13; $counter++) {
	echo"<option value=\"$counter\">$provinces[$counter]</option>\n";
}
echo "</select>\n";
?>
<br>
<input type="submit" value="Go!">
</form>

provinces2.php
PHP:
<?


$cities = array(
	0=> "St. Johns",
	"Halifax",
	"Frederiction",
	"Charlottetown",
	"Quebec City",
	"Toronto",
	"Winnipeg",
	"Regina",
	"Edmonton",
	"Victoria",
	"Iqualuit",
	"Yellowknife",
	"Whitehorse"
);


echo "The Provincial Capital is $cities[$theprovinces]<br>\n";

?>

Hehe...I changed the cities.
 
Last edited:
Thanks.

This is just an introduction lesson (Buy the book "Beginning PHP4", it's great) to the for(){} loop.

The only reason my first one didn't work was because I was telling it to print $theprovince instead of $theprovinces.

I spent a half hour looking over this. I'm stupid. :biggrin2:
 
Back
Top