Jump to content

[SOLVED] Search Results Page


rawky1976

Recommended Posts

I've taken this code from the web and modified it, I just get a blank space on the page where the results should be!

 

<?

 

$con = mysql_connect("localhost","somename","somepassword");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("somedatabase", $con);

 

if ($search) // perform search only if a string was entered.

{

$srch="%".$search."%";

$query = "select * from document WHERE keywords LIKE '$srch'";

 

$result = mysql_db_query("somedatabase", $query);

 

if ($result)

{

echo "Here are the results:<br><br>";

echo "<table width=90% align=center border=1><tr><td align=center bgcolor=#00FFFF>Document Name</td><td align=center bgcolor=#00FFFF>Keywords</td><td align=center bgcolor=#00FFFF>About</td></tr>";

 

while ($r = mysql_fetch_array($result)) {

$dn = $r["document_name"];

$kw = $r["keywords"];

$abt = $r["about"];

echo "<tr><td>$dn</td><td>$kw</td><td>$abt</td></tr>";

}

echo "</table>";

} else { echo "problems...."; }

} else {

echo "Search string is empty. <br> Go back and type a string to search";

}

?>

 

Does anybody know why please?

Link to comment
https://forums.phpfreaks.com/topic/49293-solved-search-results-page/
Share on other sites

try putting this at the top of your page:

 

error_reporting(E_ALL);

ini_set('display_errors', '1');

 

before you define $con. This may help diagnose the problem. I could be wrong here but should there not be a '@' before mysql_select_db?

 

 

I just noticed I forgot to add php after the <? !!!

 

After trying your suggestion I now get: -

 

Notice: Undefined variable: search in C:\Inetpub\wwwroot\searchResults.php on line 86

Search string is empty.

Go back and type a string to search

 

You are not defining $search anywhere. The script was probably developed with REGISTER_GLOBALS enabled - which is a bad thing. You need to use $_POST['search'] instead.

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.