Can anyone tell me whats gone wrong?
I get the following message when i try to submit a search.
"Supplied argument is not a valid MySQL result resource in '(location of file)' in line 100."
<head>
<title>search engine</title>
</head>
<form action="search.php" method="post">
Enter Your Query:
<input type="text" name="search">
<input type="submit" name="submit" value="Submit!">
</form>
<table border="1" width="90%" cellpadding="2">
<?PHP
include "./common_db.inc";
$link_id = db_connect();
if(!$link_id) die(sql_error());
$db=mysql_connect($dbhost, $dbusername, $dbuserpassword);
if(!mysql_select_db("solution_db", $db)) die(sql_error());
if (!IsSet($search)){
$search="";
}
$search=stripslashes($search);
$searchtext = htmlentities($search);
if($search!=""){
$params = split(" ", $search);
$InQuotedString = 0;
$tokNum = 0;
$tokens = array();
//Build Tokens
$tokens[$tokNum] = "";
for($i=0; $i<count($params); $i++){
if(!IsSet($tokens[$tokNum])){
$tokens[$tokNum] = "";
}
$param = $params[$i];
if(ereg("^\"", $param) || ereg("^[+-]\"", $param)){
$InQuotedString = 1;
}
if($InQuotedString == 1){
$tokens[$tokNum] .= ereg_replace("\"", "", $param) . " ";
}
else{
$tokens[$tokNum++] = $param;
}
if(ereg("\"$", $param)){
$InQuotedString = 0;
$tokens[$tokNum] = chop($tokens[$tokNum]);
$tokNum++;
}
}
echo "<p>";
$fields[] = "problem";
$fields[] = "solution";
$SQL = "select id, create_date, problem, solution, link from
solution where (";
for($i=0; $i<count($tokens); $i++){
for($x=0; $x<count($fields); $x++){
$token = ereg_replace(" $", "", $tokens[$i]);
if(ereg("^\\+", $token)){
$token = ereg_replace("^\\+", "", $token);
$SQL .= "$fields[$x] like '%$token%'";
if($x<count($fields)-1){
$SQL .= " OR ";
}
}
elseif(ereg("^\\-", $token)){
$token = ereg_replace("^\\-", "", $token);
$SQL .= "$fields[$x] NOT like '%$token%'";
if($x<count($fields)-1){
$SQL .= " AND ";
}
}
else{
$SQL .= "$fields[$x] like '%$token%'";
if($x<count($fields)-1){
$SQL .= " OR ";
}
}
}
if($i<count($tokens)-1){
$SQL .= ") AND (";
}
else{
$SQL .= ")";
}
}
$limit=" limit 20";
$SQL .= " order by create_date" . $limit;
$result = mysql_query($sql);
} 'Line 100'
while ($row = mysql_fetch_array($result)) {
print("<tr><td bgcolor=\"#0077ff\"><b>");
printf("<br>ID: %s<hr></b>\n",
$row["id"]);
printf("<br>Create_Date: %s<hr>\n",
$row["create_date"]);
printf("<br>Problem: %s<hr></b>\n",
$row["problem"]);
printf("<br>Solution: %s</td></tr>\n",
$row["solution"]);
printf("<br>Link: %s</td></tr>\n",
$row["link"]);
}
?>
</table></body>