Hi i am trying to build a page which allows a user to search a name in a table sorted in MySql, the search will produce a list of records that is met by the search, this is what i have written but it doesnt work, the way i am trying to work it is, if the user has not entered a word it gives a error message otherwise it looks at the keyword that has been typed by the user and queires the relevent table and the it will produce a list of records
<?php
if ($_POST['submitform']) {
if(empty($_POST['keywords']))
{
echo 'You need to enter a word to search';
if (isset($HTTP_REFERER)) {echo "<a href='$HTTP_REFERER'>BACK</a>"; } //this is php coding to create a hyperlink back button
else {echo "<a href='javascript:history.back()'>BACK</a>";
}
exit;
}
$conn = mysql_connect("localhost","root","") or die("Could Not Connect To The Database"); // this is the code for connection to the database created if cannot
mysql_select_db("styledynamix",$conn) or die("Could Not Select The Database");
if (isset($_GET['keywords'])) {
$sql = "SELECT *, MATCH (subject,body) ".
"AGAINST ('". $_GET['Keywords'] . "') AS score " .
"FROM suppliers ".
"WHERE MATCH (subject,body) ".
"AGAINST ('" . $_GET['keywords']."') " .
"ORDER BY score DEC";
$query = "SELECT supplier_id,supplier_name,supplier_reg_number, FROM suppliers";
$result = mysql_query($sql,$conn)or die('Could not perform search; ' . mysql_error());
$NumRows=mysql_num_rows($result);
}
else;
if($NumRows>0){
//get the first row and begin the table.
$row = mysql_fetch_assoc ($result);
//reset the result set back to the first row and display the data set.
mysql_data_seek ($result, 0);
while ($row = mysql_fetch_row ($result)) {
echo "<tr valign=top>";
echo "<td bgcolor=#93B0B4 colspan=3></td>";
echo "</tr>";
print "<TR>\n";
print "<TD>$row[0]</TD>";
print "<TD>$row[1]</TD>";
print "<TD>$row[2]</TD>";
print "<TD>$row[3]</TD>";
print "<TD>$row[4]</TD>";
}
?>
it doesnt seem to work, as i am finding it very difficult to make this page