i want help with php list menu

Discussion in 'PHP' started by vk88, May 1, 2010.

  1. #1
    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!
     
    vk88, May 1, 2010 IP
  2. lorkan

    lorkan Peon

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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
     
    lorkan, May 1, 2010 IP
    europartners likes this.
  3. vk88

    vk88 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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! :D
     
    vk88, May 2, 2010 IP
  4. easic

    easic Active Member

    Messages:
    37
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    70
    #4
    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
     
    easic, May 2, 2010 IP
    lorkan likes this.
  5. lorkan

    lorkan Peon

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Exactly, the switch should be at the VERY TOP of you page. Before anything else!
     
    lorkan, May 9, 2010 IP