Sweeney Posted March 31, 2009 Share Posted March 31, 2009 Okay I am trying to make a simple search feature were I am joining two columns in my table to pop out a simple response. However I can't get it to recognize what I'm trying to do. The issue is it keeps telling me it can't find the search phrase even though I am searching for items I know are in the table. Here is the code. Help Please!! <?php require "../_admin/config.php"; ?> <?php $phrase = array_key_exists('phrase', $_POST) ? trim(stripslashes(strip_tags($_POST['phrase']))) : ''; if(empty($phrase)){ echo "\n".'<p>No words placed in the search box. </p>'; }else{ // SQL injection prevention (double quote mark is allowed here but should probably be disallowed) $phrase = strtr($phrase, ',/\*&()$%^@~`?;', ' '); $phrase = trim($phrase); $phrase = str_replace('#180', '', $phrase); echo "\n".'<p>Searching for <i>'.htmlspecialchars($phrase).'</i>... </p>'; $key = 'text_index'; // Beware of the re-definition of $s in this query. $phrase = html_entity_decode($phrase, ENT_QUOTES); $res = mysql_connect($host, $user, $pass) or die(mysql_error()); mysql_select_db($db) or die(mysql_error()); if(!($res =mysql_query( 'SELECT `page_id` AS s, `link` AS c, `vid_title`, `vid_desc`, `hidden` FROM `'.$opts['videos'].'` WHERE `hidden` <> "1" AND MATCH(`vid_title`, `vid_desc`) AGAINST ("'.$phrase.'") LIMIT 10' ))){ echo "\n".'<p>No results for: <i class="red">'.$phrase.'</i></p>'; }else{ if(mysql_num_rows($res) == 0){ echo "\n".'<p>The search engine cannot find the page you are looking for.</p>'; echo "\n".'<p>This could be because it could not find any pages containing <i>'.$phrase.'</i>'; echo "\n".'<p>Alternatively, it might have found too many pages, and could not decide which one you wanted.</p>'; }else{ $i = 0; while($row = mysql_fetch_array($res)){ $s = substr(stristr(strip_tags($row['vid_title']), $phrase), 0, 120); if($s == ''){ $s = substr(strip_tags($row["vid_desc"]), 0, 120); } $i++; echo "\n".'<p>'.$i.'.) <a href="results.php?page_id='.$row['s'].'">'.htmlentities($row['c']).' - '.htmlentities($row['vid_title']).'</a> ... '.$s.'...</p>'; } } } // Save searches to monitor user activity $phrase_qry = sprintf("INSERT INTO vs_searches (page_id, phrase, ip) VALUES ('', '%s', '%s')", addslashes($phrase), addslashes($ua['ip'])); if(!($phrase_res = mysql_query($phrase_qry))){ $opts['error_msg'] .= 'Insert failed for search phrase'."\n".$phrase_qry."\n"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/151975-solved-search/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.