Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/forums/php/)
-   -   php search form.... (http://www.go4expert.com/forums/php-search-form-t12743/)

mia_tech 6Aug2008 13:56

php search form....
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

//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 Code:

<form name="search" method="post" action="search1.php">
Seach for: <input type="text" name="find" />
<input type="submit" name="search" value="Search" />

I appreciate any help on how to get this done

thanks in advance

asha 17Oct2008 10:52

Re: php search form....
Just use a simple OR match in all the fields you want to search.

All times are GMT +5.5. The time now is 17:31.