PDA

View Full Version : create a search function for my website


dazzclub
02-26-2008, 06:17 PM
Hi guys and girls,

I would like to implement a search facility on my site where users can search for a product quickly.

I've looked around finding some tutorials, no luck, hope you guys can help me out.

Here is my php code.

<?php
require_once("includes/connection.php");

$search = mysql_real_escape_string($_POST['search']);

$query= "SELECT * FROM 'products' WHERE $search LIKE '%$searchterm%'";
$result = mysqli_query($db, $query)or die(mysql_error() . "<p>With query:<br>$query");

while ($row = mysql_fetch_assoc($result)){
echo $row['name'].'<br>';
}

?>




Here is my html form

<form name="form1" id="form1" method="POST" action="searchDataBase.php">
<ul style="list-style-type:none;">
<li><input type="text" name="search" id="search" ></li>
<li><input type="image" name="submit" value="submit" src="images/search-bttn.png" id="submit" title="Click here to search"></li>
</form>
[/code[

when i try to use the search facility this shows up after i submit it
[code]
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in E:\wamp\www\drinkpromo\searchDataBase.php on line 7

With query:
SELECT * FROM 'products' WHERE hello LIKE '%hello%



cheers

davidj
02-26-2008, 06:21 PM
follow my tutorial vids to get an idea of coding and then come back