Kirk ERW
Kirk ERW

Reputation: 167

test on SELECT Menu values

I have a select menu, and i'd like to make a mysql query depending on the chosen value. I have created a function that compares the selected value with, here's my form of select menu:

<form method="POST"  action = "choose-type.php">
    <select name="Value" SIZE=1>
        <option value="'Clothes'">CLOTHES
        <option value="'Wine'">WINE
        <option value="'Bread'">BREAD
        <option value="'Milk'">MILK
    </select>
    <div>
      <input Value="submit" align="middle" > 
    </div>
</form>

<?php    
   $Value = $_POST['Value'];
   $DST = array('\'CLOTHES\'','\'WINE\'');
   function type() {
    $TYPE2 = ' ';
    if (($Value == $DST[0]) or ($Value == $DST[1])) {
           $TYPE2 = 'first';
        }
        else {
            $TYPE2 = 'second';
        }
    return $TYPE2;
   }

My code doesn't work :/ it always returns first even if i choose 'milk for example' can someone correct my code please ???

Upvotes: 1

Views: 53

Answers (2)

Stephen O&#39;Flynn
Stephen O&#39;Flynn

Reputation: 2329

You should double-check what's coming in on the $_POST before you run your function. It looks like your case is causing problems; you're comparing 'CLOTHES' == 'Clothes', which isn't the same. Add the die() line below so you can see what the form sends and act accordingly. Obviously remove it again when you know what to do.

die(var_dump($_POST));
$Value = $_POST['Value'];

$DST = array('\'CLOTHES\'','\'WINE\'');
function type() {
 $TYPE2 = ' ';
 if (($Value == $DST[0]) or ($Value == $DST[1])) {
        $TYPE2 = 'first';
     }
     else {
         $TYPE2 = 'second';
      }
 return $TYPE2;

Upvotes: 0

Yogesh Suthar
Yogesh Suthar

Reputation: 30488

you have to pass $Value,$DST inside function

function type() {
    $Value = $_POST['Value'];
    $DST = array('\'CLOTHES\'','\'WINE\'');
    $TYPE2 = ' ';
    if (($Value == $DST[0]) or ($Value == $DST[1])) {
       $TYPE2 = 'first';
    }
    else {
        $TYPE2 = 'second';
    }
    return $TYPE2;
}

Upvotes: 3

Related Questions