Jump to content

error messages not echoed.


Bazzaah

Recommended Posts

Hey there

 

I've adapted the search code from the tutorial on this site here

 

http://www.phpfreaks.com/tutorial/simple-sql-search

 

for a project I've been working on but have an error.

 

The search works just fine but if either of the messages I've included are tripped (zero search characters or nothing found) then I get a blank screen and the error message is not echoed. (The vanilla code works fine - the error has arisen through the changes I needed to make).

 

I don't know why this is happening and would appreciate some help please.

 

Thanks in advance for any help.

 

session_start();

// check session variable

if (isset($_SESSION['first_name']))
  {
include ('includes/header_loggedin.html');

//db connection info deleted  

$error = array();

//get search term, strip it

if (isset($_GET['search'])) {
$searchTerms = trim($_GET['search']);
$searchTerms = strip_tags($searchTerms); // remove any html/javascript.

   
   if (strlen($searchTerms) < 1) {
      $error[] = 'Search terms must be longer than 1 character.';
   }else {
      $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection.
   }
   
//formulate query
   if (count($error) < 1) {
$query = "SELECT * FROM table WHERE row LIKE '%{$searchTermDB}%'";

//make the query

$result = mysql_query($query) or die(mysql_error());

//display the results
if (mysql_num_rows($result) < 1) {
         $error[] = "Your search term yielded no results.";
      } else {
	while ($endresult = mysql_fetch_array($result)) {
		echo '<br />';
		echo 'This is what we found';
		echo '<br />';
      echo '<a href="newpage.php?w=' . $endresult['row'] . '">' . $endresult['row'] . '</a>';
  		}	
}
}
}
} 

Link to comment
https://forums.phpfreaks.com/topic/247330-error-messages-not-echoed/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.