TheJoshMan
11-01-2008, 02:54 PM
Ok, so i'm technically still a virgin when it comes to PHP. I am trying to learn on my own, but I keep getting stuck on this script I'm trying to write.
Here's what I'm trying to do:
Page 1:
has a dropdown box where user can select a value
also has an array which is used to fill the select box
Page 2:
has another array of items which correspond to the Page 1 array
has processing script to handle the submitted info and match the corresponding items then echo outcome
For some reason, everytime I submit the value from the dropdown box it simply echos ALL items in the array rather than just the one that corresponds.
Here's an example (Page 1):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title> Blah </title>
</head>
<body>
<h2>Number Matcher</h2>
<form method="post" action="script.php">
<label>Please select a number:</label>
<select name="number">
<?php
$numbers = array(0=> "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten");
for ($counter=0; $counter < sizeof($numbers); $counter++)
{
echo "<option>$numbers[$counter]</option>";
}
echo "</select>";
for ($counter=0; $counter < sizeof($numbers); $counter++)
{
echo "<input type=hidden name=hidden[] value=$numbers[$counter]>";
}
echo "<input type=submit name=submit value=Submit></form>";
?>
</body>
</html>
And here's Page 2:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title> Blah </title>
</head>
<body>
<?php
$digit = $_POST['number'];
$numero = array (0=> "Uno", "Dos", "Tres", "Cuatro", "Cinco", "Seis", "Siete", "Ocho", "Nueve", "Diez");
for ($counter=0; $counter < sizeof($numero); $counter++)
{
if ($hidden[$counter] == $numbers[$counter])
{
echo "The number <strong>$digit</strong> is the same as <em><strong>$numero[$counter]</strong></em> in Spanish.";
}
}
?>
</body>
</html>
And if you need a working link to see the outcome problems... then here it is too: http://www.eight7teen.com/DD/php-test/numbers.php
Also, I forgot to mention that when I test this locally on my machine... When I submit the data from the first page, it takes me to the second page and prints the entire array... (see below)
http://www.eight7teen.com/DD/php-test/locally.jpg
However, when I submit the data from the first page on my server... It takes me to the second page but it's completely blank. What is going on? The files are the exact same on the server as they are on my local machine!?!
Here's what I'm trying to do:
Page 1:
has a dropdown box where user can select a value
also has an array which is used to fill the select box
Page 2:
has another array of items which correspond to the Page 1 array
has processing script to handle the submitted info and match the corresponding items then echo outcome
For some reason, everytime I submit the value from the dropdown box it simply echos ALL items in the array rather than just the one that corresponds.
Here's an example (Page 1):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title> Blah </title>
</head>
<body>
<h2>Number Matcher</h2>
<form method="post" action="script.php">
<label>Please select a number:</label>
<select name="number">
<?php
$numbers = array(0=> "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten");
for ($counter=0; $counter < sizeof($numbers); $counter++)
{
echo "<option>$numbers[$counter]</option>";
}
echo "</select>";
for ($counter=0; $counter < sizeof($numbers); $counter++)
{
echo "<input type=hidden name=hidden[] value=$numbers[$counter]>";
}
echo "<input type=submit name=submit value=Submit></form>";
?>
</body>
</html>
And here's Page 2:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title> Blah </title>
</head>
<body>
<?php
$digit = $_POST['number'];
$numero = array (0=> "Uno", "Dos", "Tres", "Cuatro", "Cinco", "Seis", "Siete", "Ocho", "Nueve", "Diez");
for ($counter=0; $counter < sizeof($numero); $counter++)
{
if ($hidden[$counter] == $numbers[$counter])
{
echo "The number <strong>$digit</strong> is the same as <em><strong>$numero[$counter]</strong></em> in Spanish.";
}
}
?>
</body>
</html>
And if you need a working link to see the outcome problems... then here it is too: http://www.eight7teen.com/DD/php-test/numbers.php
Also, I forgot to mention that when I test this locally on my machine... When I submit the data from the first page, it takes me to the second page and prints the entire array... (see below)
http://www.eight7teen.com/DD/php-test/locally.jpg
However, when I submit the data from the first page on my server... It takes me to the second page but it's completely blank. What is going on? The files are the exact same on the server as they are on my local machine!?!