On 24/12/14 02:10, Tim Dunphy wrote:
Hi all,
I'm following some examples from PHP and MySQL web development by Luke
Welling and Laura Thompson. I'm trying to pass a value from a drop down
selection list via $_POST. But the wrong value ends up in the variable.
Here's the section of code that I seem to be having a problem with:
<form action="processorder.php" method="post">
..... /* more code here */
<tr>
<td>How did you find Bob’s?</td>
<td><select name="find">
<option value = "a">I’m a regular customer</option>
<option value = "b">TV advertising</option>
<option value = "c">Phone directory</option>
<option value = "d">Word of mouth</option>
</select>
</td>
</tr>
From that section of HTML I'm expecting to find the values a,b,c or d in the
$_POST['find'] variable.
The code that receives this value in the php script is this:
$find = $_POST['find'];
... /* more code here */ ...
if ($find == "a") {
echo "<p>Regular customer.</p>";
} elseif ($find == "b") {
echo "<p>Customer referred by TV advert";
} elseif ($find == "c") {
echo "<p>Customer referred by phone directory</p>";
} elseif ($find == "d") {
echo "<p>Customer referred by word of mount</p>";
} else {
echo "<p>We do not know how this customer found us.</p>";
}
However the message that displays in the php script is always: echo "<p>We do
not know how this customer found us.</p>";
If I put in an echo statement to actually look at whats' in the $find
variable, instead of a,b,c or d what I'm finding instead are the full phrases
associated with the letter in the table.
For example if I were to select a) from the drop down list, what ends up in
the $find variable is instead "<p>Regular customer.</p>".
This really seems like some conceptual error on my part. Can someone please
point out to me where I'm going wrong in expecting the letter in to end up in
the variable?
The code is easily fixed by setting up the logic like this:
if ($find == "I’m a regular customer") {
echo "<p>Regular customer.</p>";
etc
But that's a little cumbersome. How can I go about getting the desired result?
I'm enclosing the two pages of code for greater context.
Thanks!!!
Tim
--
GPG me!!
gpg --keyserver pool.sks-keyservers.net <http://pool.sks-keyservers.net>
--recv-keys F186197B
You probably need to attach the form page too - I don't see anything in
processorder.php that is causing that problem (there a few things I'd do
differently, and I'm not sure about the logic that decides nothing was ordered,
but that's not the question...)
Cheers
Pete
--
Peter Ford phone: 01580 893333 fax: 01580 893399
Justcroft International Ltd. www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent TN12 0AH United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php