Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Form Problem

  1. #1
    New Coder
    Join Date
    Feb 2008
    Posts
    74
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Form Problem

    Hi
    I am making a search form that returns the word that the user searched as an experiment, this is the code i am using on index.html
    Code:
    <html>
    <body>
    
    
    <center><form action="welcome.php" method="post">
    <input type="text" size="40"  name="name" /></center>
    
    <center><input type="submit" value="Search" /></center>
    </form>
    
    </html>
    Then for the second page welcome.php i am using
    Code:
    <?php echo $_POST["name"]; ?>
    What i want is firstly for what the user searches to be in the url for example in a google search for php http://www.google.co.uk/search?hl=en...e+Search&meta= php is in the url how can i make mine so it is /search?PHP for example?

    Also how can i make it so on the second page the search box is there?

    Thanks

  • #2
    New Coder
    Join Date
    Sep 2006
    Posts
    92
    Thanks
    4
    Thanked 1 Time in 1 Post
    Quote Originally Posted by ojsimon View Post
    What i want is firstly for what the user searches to be in the url for example in a google search for php http://www.google.co.uk/search?hl=en...e+Search&meta= php is in the url how can i make mine so it is /search?PHP for example?
    You mean like this?

    PHP Code:
    <?php 
      $search 
    $_POST["name"];
      echo (
    "<a href=\"http://www.google.co.uk/search?$search\">http://www.google.co.uk/search?$search</a>");
    ?>
    Quote Originally Posted by ojsimon View Post
    Also how can i make it so on the second page the search box is there?
    Don't redirect to a new page but put the php code on in the same page as your search box. That way if a search is done it shows the search and if not then it doesn't (example below assumes that the file itself is called welcome.php - so it is 1 file and not 2)

    PHP Code:
    <html>
    <body>


    <center><form action="welcome.php" method="post" target="_self">
    <input type="text" size="40"  name="name" /></center>

    <center><input type="submit" value="Search" /></center>
    </form>

    <?php 
      $search 
    $_POST["name"];
      if (!empty(
    $search)){
        echo (
    "<a href=\"http://www.google.co.uk/search?$search\">http://www.google.co.uk/search?$search</a>");
     }
    ?>
    </body>
    </html>
    Nemesis War
    Online browser based space combat game.
    It's free, it's great, you'll love it.
    Come join us at http://www.nemesiswar.net/

  • #3
    Regular Coder
    Join Date
    Feb 2007
    Location
    Canada
    Posts
    924
    Thanks
    10
    Thanked 56 Times in 55 Posts
    <center>

    <form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" >

    <input type="text" size="40" name="name" value = "enter search words here..." /></center>

    <center><input type="submit" value="Search" /></center>
    </form>

    <?php
    $search = $_POST["name"];
    if (!empty($search)){
    echo ("<a href=\"http://www.google.co.uk/search?$search\">http://www.google.co.uk/search?$search</a>");
    }
    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •