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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.