Using double quotes ("), to create strings, PHP will handle any $ sign in
the string as a variable.. There are two ways around this.
$Entrees= array('Steak ($9)', 'Pizza ($7)', 'Pasta ($6)');
Or
$Entrees=array("Steak (\$9)", "Pizza (\$7)", "Pasta (\$6)");
also, when using echo in this context:
echo "<form method="POST" action="menu2.php">";
You need to escape out the "'s within the string. IE:
echo "<form method=\"POST\" action=\"menu2.php\">"
I use single quotes instead.
Here is the fixerupped version of the code.
<html>
<head>
<title>Charlies Menu</title>
</head>
<body>
<?php
$Entrees = array('Steak ($9)', 'Pizza ($7)', 'Pasta ($6)');
echo '<form method="POST" action="menu2.php">'; // this ; was missing
echo 'Which of the following would you like as an entree?';
echo '<select name="ListBox1">';
echo '<option selected value="">Select...</option>';
echo '<option value="' . $Entrees[0] . '">' . $Entrees[0] . '</option>';
echo '<option value="' . $Entrees[1] . '">' . $Entrees[0] . '</option>';
echo '<option value="' . $Entrees[2] . '">' . $Entrees[0] . '</option>';
echo '</select><br><br>';
echo '<input type="submit">';
echo '</form>';
?>
</body>
</html>
or even better, instead of typing out each Array item individually:
<html>
<head>
<title>Charlies Menu</title>
</head>
<body>
<?php
$Entrees = array('Steak ($9)', 'Pizza ($7)', 'Pasta ($6)');
echo '<form method="POST" action="menu2.php">'; // this ; was missing
echo 'Which of the following would you like as an entree?';
echo '<select name="ListBox1">';
echo '<option selected value="">Select...</option>';
$records = count($Entrees); // count the number of elements within the
array
// loop through the array showing each record within the array
for ($i = 0; $i < $records; $i++)
{
echo '<option value="' . $Entrees[$i] . '">' . $Entrees[$i] .
'</option>';
}
echo '</select><br><br>';
echo '<input type="submit">';
echo '</form>';
?>
</body>
</html>
Thsi way, you can add new elements to the $Entrees array, without having to
add extra code to your output.
-----Original Message-----
From: Wade [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, 14 January 2003 3:26 PM
To: [EMAIL PROTECTED]
Subject: [PHP-WIN] initialize variables
01132003 2014 CST
Ok. Im so happy that you guys explained the $_POST thing to me. Just
implementing that in every tutorial after that worked.
Now, I have another problem.
This, again, is right out of the book. Everything in this book is in
<?php tags. This code brings up a blank page. When you look at the
source code through the browser all you see is
<html><head></head></html>. What is it that I cannot see and my book
will not tell me?
Wade
***************
<html>
<head>
<title>Charlies Menu</title>
</head>
<body>
<?php
$Entrees=array("Steak ($9)", "Pizza ($7)", "Pasta ($6)");
echo "<form method="POST" action="menu2.php">"
echo "Which of the following would you like as an entree?";
echo "<select name='ListBox1'>";
echo "<option selected value=' '>Select...</option>";
echo "<option>$Entrees[0]</option>";
echo "<option>$Entrees[1]</option>";
echo "<option>$Entrees[2]</option>";
echo "</select><br><br>";
echo "<input type="submit">";
echo "</form>";
?>
</body>
</html>
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php