tags:

views:

33

answers:

2

I am trying to grab data a user selected from a drop down menu. User either selects view all, option 1, option 2, or option 3. I have a function called getUserCategory that stores the user choice in a variable called $category. I tried getting the value of the function by doing:

return $category inside the getUserCategory function

and then writing:

$catChoice = getUserCategory();

I wasn't able to display $catChoice in the browser when I tried to do an echo statement.

echo $catChoice;

I also tried echoing inside the function

echo $cateogry; 

but still, not able to display the value in the browser.

Form

    <form action="register_script.php" name="frm" method="post">
        <select name="category" id="category">
            <option value="viewall">View All</option>
            <option value="option1">option1</option>
            <option value="option2">option2</option>
            <option value="option3">Sandals</option>
       </select>

      <input type="submit" value="Go" />  

PHP

 //call function getUserCategory ---------------------------------------------------        
        getUserCategory();
        //$catChoice = getUserCategory();

//function getUserCategory --------------------------------------------------------     
        function getUserCategory() {
            echo "<br/>" . "In the getUserCategory function Msg 1" . "<br/>";
            $category = $_POST["category"]; 
            //return $category;
            echo $cateogry . "<br/>";
            echo "In the getUserCategory function Msg 2";
        }
+4  A: 

you have a spelling mistake

echo $cateogry . "<br/>";

should be

echo $category . "<br/>";
Galen
@Galen aah! thanks for catching that!
jc70
@crewof1 dont forget to accept the answer using tick mark ;)
rahim asgari
@Galen I had to re-read your answer at least 3 times before I saw the difference between those two lines of code -- good catch!
mlms13
A: 

instead of echo $cateogry use die($cateogry)

rahim asgari