开发者

Grab data from a form and display in browser (PHP)

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 th开发者_开发问答e 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";
        }


you have a spelling mistake

echo $cateogry . "<br/>";

should be

echo $category . "<br/>";


instead of echo $cateogry use die($cateogry)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜