search php mysql

hi everyone, I am actually very new to php and mysql… I am creating my web site and i want to have a search on the pages, i had created the datebase …i had check some tutorials on the web but i havent been able to understand it or it doesnt work…plz ,plz if someone can give me a little of orientation and help me with this i will appreciated thnks

Here is a great source for real world practical use tutorials - and here is a link to the search engine tutorial

Searching is similar to selecting, just a few minor changes.

Connect to the DB using PDO dbconnect.php:
//Set the host, username, password and db name in variables
$db_myHost = “localhost”;
$db_myUser= “user”;
$db_myPassword = “pass”;
$db_myDatabase = “db”;

//Connect to the db
$dbconn = new PDO(‘mssql:host=’.$db_myHost.’;dbname=’.$db_myDatabase, $db_myUser, $db_myPassword);

//Test the connection
$dbPDO = new PDO(‘mssql:host=’.$db_myHost.’;dbname=’.$db_myDatabase, $db_myUser, $db_myPassword);
catch (PDOException $e)
//echo "Error!: " . $e->getMessage() . "

Search using a form search.php:

<?php require_once("dbconnect.php");?> Search <?php //Check if the form was submitted if(isset($_POST['submit'])) { //$query = $dbconn->prepare means to prepare the select query $query = $dbconn->prepare(" SELECT id, title FROM tablename WHERE title LIKE :title "); //Get the query from the form $q = $_POST['q'];

//Declare the search term

//Get the results
$results = $query->fetchAll();

//Enter the results into a foreach loop
foreach ($result AS $results){

//Output the result
echo "$result[‘title’];
}else {
//form wasnt subitted show the form
echo ’

Enter a query:
'; } ?> [/php]

That’s just a basic example.

Sponsor our Newsletter | Privacy Policy | Terms of Service