sorin21us Posted March 29, 2008 Share Posted March 29, 2008 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 https://forums.phpfreaks.com/topic/98510-search/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.