< ?php
DEFINE (‘DB_USER’, ‘myname’); // Insert your database username into the quotes.
DEFINE (‘DB_PASSWORD’, ‘mypassword’); // Insert your database password into the quotes.
DEFINE (‘DB_HOST’, ‘localhost’); // This will most likely stay the same.
DEFINE (‘DB_NAME’, ‘news’); //Insert your actual database name in the quotes.
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die (‘Could not connect to MySQL: ‘ . mysql_error()); //@ is to o not show errors on the page
@mysql_select_db (DB_NAME) OR die(‘Could not select the database: ‘ . mysql_error() );
if(isset($_POST[‘submit’])){ //if the form was submited
$search = $_POST[‘search’]; //put in $search what the user entered
if(trim($search) == ){ //if the user didn’t type a keyword
$errors = ‘Please enter a keyword
 
;
}
if($errors == ){ //if we don’t have any errors
// $search holds what the user typed
$query = "SELECT * from news WHERE title LIKE ‘%$search%’ OR post LIKE ‘%$search%’ OR author LIKE ‘%$search%’";
$result = mysql_query($query) or die(mysql_error());
if($result){
display_form();//redisplay the search box
echo "
found "
. mysql_num_rows($result)." results
 
"
;
echo "

    ";
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
    $mess=$row[‘post’];
    $view = ‘page.php?id=’.row[‘id’];
    echo "

  • ".$row[‘title’].
  •  
    ‘;
    echo

    ‘.snippet($mess, 200, true).
     
    ;//bring only 200 chars from datatabase
    }
    }
    }
    }
     
    if(!isset($_POST[‘submit’]) || $errors != ){
    echo $errors;
    display_form();//display first time the search box
    }
     
    function display_form(){
    ?>

 

fonte: www.sastgroup.com