Forum Moderators: coopster
<form action = 'search2.php' method = 'GET'>
<input type = 'text' size='90' name = 'search'></br></br>
<input type = 'submit' name = 'submit' value = 'Search'></br></br></br>
</form>
<?php
$button = $_GET ['submit'];
$search = $_GET ['search'];
if(!$button )
echo "you didn't submit a keyword";
else {
if(strlen($search)<=1)
echo "Search term too short";
else {
echo "You searched for <b> $search </b> <hr size='1' > </br> ";
include('admin/misc.inc');$cxn = mysqli_connect($host,$user,$passwd,$dbname) or die ("couldn't connect to server" . mysqli_error());
$search_exploded = explode (" ", $search);
foreach($search_exploded as $search_each) {
$x++;
if($x==1)
$construct .="color_name LIKE '%$search_each%'";
else
$construct .="OR color_name LIKE '%$search_each%'";
}
$construct = "SELECT * FROM RMI_style WHERE $construct";
$run = mysqli_query($cxn, $construct );
$foundnum = mysqli_num_rows($run);
if ($foundnum==0)
echo "Sorry, there are no matching result for <b> $search </b>. </br> </br> 1. Try more general words. for example: If you want to search 'how to create a website' then use general keyword like 'create' 'website' </br> 2. Try different words with similar meaning </br> 3. Please check your spelling";
else {
echo "$foundnum results found !<p>";
while( $runrows = mysqli_fetch_assoc($run ) ) {
$vendor = $runrows ['vendor_name'];
$color = $runrows ['color_name'];
$desc = $runrows ['desc'];
$styleno = $runrows ['style_no'];
$styledes = $runrows ['style_desc'];
$url = $runrows ['order_url'];
echo "<a href='$url'>$vendor $color $desc Style #$styleno</a> f$styledes</p>";
}
}
}
}
?>
The first issue is that I know I need to make certain that I am preventing sql injection, but do not know exactly where to place that code.