Jump to content

search


sorin21us

Recommended Posts

I try to do a search bar for my web site, but I don't know why this code doesn't work.

Can someone give an advise, or a better idea ?

 

//starting php

<?php

$hostname_logon = "localhost" ; 

$database_logon = "forum" ; 

$username_logon = "root" ; 

$password_logon = "password" ; 

//open database connection

$connections = mysql_connect($hostname_logon, $username_logon, $password_logon) or die ( "Unabale to connect to the database" );

//select database

mysql_select_db($database_logon) or die ( "Unable to select database!" );

 

// Get the search variable from URL

  $var = @$_GET['q'] ;

//trim whitespace from the stored variable

  $trimmed = trim($var);

//separate key-phrases into keywords

  $trimmed_array = explode(" ",$trimmed);

 

// check for an empty string and display a message.

if ($trimmed == "") {

  $resultmsg =  "<p>Search Error</p><p>Please enter a search...</p>" ;

  }

 

// check for a search parameter

if (!isset($var)){

  $resultmsg =  "<p>Search Error</p><p>We don't seem to have a search parameter! </p>" ;

  }

if(isset($var))

{

    $query = "SELECT * FROM forumtutorial_posts WHERE author LIKE '%$trimm%' OR title like '%$trimm%' OR post like '%$trimm%'" ;

    // Execute the query to  get number of rows that contain search kewords

    $numresults=mysql_query($query);

   

      $numresults = mysql_query ($query) or die ( "Couldn't execute query" );

 

    while( $row= mysql_fetch_array($numresults));

    {

        print("$row[0] and $row[1] and $row[2]");

    }

}

else

{

?>

 

<form action="{$_SERVER['PHP_SELF']}" method="get" name="search">

  <div align="center">

      <input name="q" type="text" value=" " size="15">

      <input name="search" type="submit" value="Search">

  </div>

</form>

 

<?php

}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.