php search form....

Discussion in 'PHP' started by mia_tech, Aug 6, 2008.

  1. mia_tech

    mia_tech New Member

    Joined:
    Aug 6, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I've wanted to create a search form and the search will be against table called articles with columns: title, date, info, url. This table will store information about the articles in a website, I've came up with my a very simple php script, but the problem is that it doesn't matter what you put into the search box it will return the entire table and the part of the problem is in the sql statement, which is not doing a filtering I'm using "SELECT * FROM articles" and I know I should put some sort of "WHERE * LIKE *" in the query, I just can't find the php code for it, anyway here's the php code
    Code:
    <?php
    //open connection
    $conn = mysql_connect("localhost", "root", "password") or die(mysql_error());
    //select database
    mysql_select_db("test", $conn);
    //the sql statement
    $sql = "SELECT * FROM articles";
    //execute the statement
    $data = mysql_query($sql, $conn) or die(mysql_error());
    while ($result = mysql_fetch_array($data)) {
        //giving names to the fields
        $title = $result['title'];
        $date = $result['date'];
        $info = $result['info'];
        $url = $result['url'];
        //put the results on the screen
        echo "<b>$title</b>";
        echo " ";
        echo "<b>$date</b><br>";
        echo "$info<br>";
        echo "$url<br>";
    }
    ?> 
    and here's the search form
    HTML:
    <h2>Search</h2>
    <form name="search" method="post" action="search1.php">
    Seach for: <input type="text" name="find" /> 
    <input type="submit" name="search" value="Search" />
    </form>
    
    I appreciate any help on how to get this done

    thanks in advance
     
  2. asha

    asha New Member

    Joined:
    Nov 9, 2006
    Messages:
    44
    Likes Received:
    2
    Trophy Points:
    0
    Occupation:
    Homemaker
    Location:
    Kolkata
    Home Page:
    http://whatanindianrecipe.com
    Just use a simple OR match in all the fields you want to search.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice