logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 01-31-2012, 06:58 PM   #1
sydesign
 
Join Date: Jan 2011
Posts: 41
Default Creating a search box for site

I am trying to teach myself through tutorials how to create a search box for a website for a client i have. Going through on tutorial it seems to work except i keep getting errors when i search for something on the site as if i didn't create the item in mysql database. I am not familiar with mysql or php too much can some see if there is a problem with my php? or have an ideas how i could have messed up my database set up?

the form is this:

HTML Code:
<form action="./results.php" method="get">
           <input name="input" type="text" size="30" <?php echo $_GET ['input']; ?> />
           <input type="submit" name="search" value="Search Items" />
      </form>
and here is the connected php code:

PHP Code:
<?php 
    $input 
$_GET['input'];
    
$terms explode(" "$input);
    
$query "SELECT * FROM search LIMIT ";
    
    foreach (
$terms as $each) {
        
$i++;
        if (
$i == 1)
            
$query .= "keywords LIKE '%each%' ";
        else
            
$query .= "OR keyword LIKE '%each%' ";
    }
        
    
//Connect to Database
    
mysql_connect("mysql5.000webhost.com""a1894269_marksy","cousin13");
    
mysql_select_db("a1894269_search");
    
$query mysql_query($query);
        
$numrows mysql_num_rows($query);
        if (
$numrows 0) {
        
        while (
$row mysql_fetch_assoc($query)) {
                
$id $row['id'];
                
$title $row['title'];
                
$description $row['description'];
                
$keywords $row['keywords'];
                
$link $row['link'];
            
            echo 
"<h2><a href='$link'>$title</a></h2>
            
$description<br/><br/>";
            
        }
    }
    
    else 
        echo 
"No result found for '<b>$input</b>'";
    
    
//Disconnect
    
mysql_close();
                
?>
thank you for any help!
sydesign is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:26 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com