Skip to content

Instantly share code, notes, and snippets.

Created February 6, 2011 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/813716 to your computer and use it in GitHub Desktop.
Save anonymous/813716 to your computer and use it in GitHub Desktop.
<?php
if(!empty($_POST)&& !empty($_POST['search']))
{
extract($_POST);
$search = strip_tags($search);
try{
$bdd = new PDO ('mysql:host=localhost;dbname=articles', 'aimeric','roffbmw94') or die(print_r($bdd->errorInfo()));
$bdd->exec('SET NAMES utf8');}
catch(exeption $e){
die('Erreur:'.$e->getMessage());
}
$req = $bdd->query("SELECT titre, contenu FROM articles WHERE titre LIKE'%$_search%' OR contenu LIKE'%search%' ORDER BY id");
if($req->rowCount()>0)
{
while($data = $req->fetch(PDO: :FETCH_OBJ))
{
echo '<h2>'.$data->titre.'</h2>';
echo '<p>'.$data->contenu.'</p>';
echo '<hr/>';
}
}
else
{
echo '<h2> Aucun resultat</h2>';
}
}
else
{
echo '<h2> Aucun resultat</h2>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment