hi guys can you please help me out, im trying to create a search engine for my website, what i must admit is that i am a novice coder and therefore do not know much! below is the code that i have used! Can someone please help me out or give me advice on some other code that i can use! Thank you!
Processform.php
<html>
<head><title>processform</title>
</head>
<body>
<?php
// include MySQL-processing classes
$var = @$_GET['q'];
$trimmed = trim($var);
// connect to MySQL
$dbhost = "localhost";
$dbname = "musicwebsite";
$dbuser = "username";
$dbpass = "******";
$link = mysql_connect('localhost', 'username', '******');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('musicwebsite');
if (!$db_selected) {
die('Could not select database: ' . mysql_error());
}
$keyword = mysql_real_escape_string($_POST['keyword']);
// Perform the fulltext search
$sql = "SELECT productID, ArtistName, AlbumName, year, Genre, TypeOfDisc, Price, image
FROM music WHERE MATCH(ArtistName) AGAINST ('$keyword')";
$query = mysql_query($sql) or die(mysql_error());
$row_sql = mysql_fetch_assoc($query);
$total = mysql_num_rows($query);
if($total>0) {
while ($row_sql = mysql_fetch_assoc($query)) {//echo out the results
echo ''.$row_sql['ArtistName'].'<br />'.$row_sql['Price'].'';
}
} else
{
echo '<div class="maincontainer"><h2>No results were found, Go
back and try a new search.</h2></div>'.'';
}
echo '</div>';
?>
</body>
</html>
Search engine code that i paste on every page that i want to have the search text box
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-
8859-1">
<title>MySQL-based Search Engine</title>
<link href="default.css" rel="stylesheet" type="text/css" media="screen">
<script language="javascript" type="text/javascript">
window.onload=function(){
if(document.getElementById&&document.
getElementsByTagName&&document.createElement){
var sfield=document.getElementsByTagName('form')[0].elements[0];
if(!sfield){return};
sfield.onfocus=function(){this.value=''};
sfield.onblur=function(){
if(!this.value){this.value='Enter your search term here'};
}
}
}
</script>
</head>
<body>
<h1>Music2Movies Search Engine</h1>
<div class="maincontainer">
<form method="get" action="processform.php">
<input name="searchterm" title="Enter your search
term here" value="Enter your search term here" class="searchbox" type="text">
<input name="search" title="Search Now!" value="Search" class="searchbutton" type="submit">
</form>
</div>
</body>
</html>
[ Mod Edit - bpat1434 ] Please use [noparse]
[/noparse] tags around php code and don't paste your passwords.