php search form....

mia_tech's Avatar, Join Date: Aug 2008
Newbie Member
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's Avatar, Join Date: Nov 2006
Go4Expert Member
Just use a simple OR match in all the fields you want to search.