incorrect value from form

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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="" 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 --recv-keys F186197B

Attachment: processorder.php
Description: application/httpd-php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux