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

Dr. T

New Member
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 bydoing: \[code\]return $category\[/code\] inside the getUserCategory functionand then writing:\[code\]$catChoice = getUserCategory();\[/code\]I wasn't able to display $catChoice in the browser when I tried to do an echo statement. \[code\]echo $catChoice;\[/code\]I also tried echoing inside the function \[code\]echo $cateogry; \[/code\]but still, not able to display the value in the browser.Form\[code\] <form action="register_script.php" name="frm" method="post"> <select name="category" id="category"> <option value="http://stackoverflow.com/questions/3755047/viewall">View All</option> <option value="http://stackoverflow.com/questions/3755047/option1">option1</option> <option value="http://stackoverflow.com/questions/3755047/option2">option2</option> <option value="http://stackoverflow.com/questions/3755047/option3">Sandals</option> </select> <input type="submit" value="http://stackoverflow.com/questions/3755047/Go" /> \[/code\]PHP\[code\] //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"; }\[/code\]
 
Back
Top