hello! this is my first time to post something here! i have a assignment in php. Specifically i want help to a list menu. the code is: <form id="form1" name="form1" method="post" action="main.php"> <select name="sel"> <option value="title" >browse by title</option> <option value="author">browse by author</option> <option value="editor">browse by editor</option> </select> <label for="select"></label> <label for="Submit"></label> <input type="submit" name="SEARCH" value="SEARCH" id="Submit" /> </form> What code i have to write in the page main.php that in every different option, goes to a different page. for example: when i click browse by title goes to title.php, when i click browse by author goes to author.php and when i click browse by editor goes to editor.php. i hope to understand my query. thank you very much!
Hi! The question is if you want a forward script built in, or if you want a certain sort of information shown depending on the selection the user made... anyways this code will probably be useful: $the_choice=$_POST['sel']; -- this defines their choice as $the_choice PHP: Now a simple switch can solve your solution: switch ($the_choice) { case title: header('Location: http://www.example.com/title.php'); break; case author: header('Location: http://www.example.com/author.php'); break; case editor: header('Location: http://www.example.com/editor.php'); break; default: code to be executed if $the_choice is different from any other alternative; --(optional) } PHP: I hope this will help you enough on your way! Best regard, Lorkan Webprogrammer for http://www.stockholmbudget.com
hello again. sorry if i bother you again but i have one more problem. i did what you write to me but it doesn't seem to work. it shows me this message: Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\dokimi\index.php:76) in C:\xampp\htdocs\dokimi\index.php on line 81 do you know what means that?? thanks a lot!
That means you have to put that code before any output to the user. Even a single new-line isn't allowed. Same for debug outputs. Just make sure the very first line is a php code, not html. <?php $var header("Location: $var"); ?> Code (markup): Something like that