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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Search Form Question...

    I have a search form set up... First page is the search fields second page is the results... I really want the whole thing to be together so I thought the best way was just do a php include on the second page for the search page. The only thing is now each time the page loads it runs the search with no fields, so basically outputs everything in the database... Anyone have a better idea of how to do this?

  • #2
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    PHP Code:
    <html>
    <head>
    <title>search</title>
    </head>
    <body>

    <form action="" method="POST">
    <input type="text" name="search_term">
    <input type="submit" name="submit" value="search">
    </form>

    <?php
    if (isset($_POST['submit']))
    {
        
    // do search and display results
    }
    ?>

    </body>
    </html>

  • #3
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    well it would help if you could post your code, but I'm pretty sure I understand the problem. A switch statement to see whether the form button has been pressed will do it.

    Search_form.inc
    PHP Code:
    <form action=<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    Search <input type="text" name="search" />
    <input type="submit" value="Search" name="button" />
    </form>
    The form above can be a separate file and included in the default case or can be echoed in the default case.

    Search.php
    PHP Code:
    <?php
    switch($_POST['button']){
        case 
    "Search":
       
    //code here 
       
    break;
      default:
        include(
    "Search_form.inc");
    //end switch
    ?>
    Last edited by fl00d; 07-19-2007 at 04:25 PM. Reason: forgot to close [php] tags

  • #4
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hi guys... I added the above code
    PHP Code:
    if (isset($_POST['submit'])) 
    at the top of the search.php page, then on the results page I have my include but when you run the results page it srtill gives me all the results... any ideas?

  • #5
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    Post your code...


  •  

    Posting Permissions

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