Question : Search page not returning results in PHP MySQL

Hello Everyone...

I have been fighting with this search page I am building for a client...

When building it in Dreamweaver, Everything seems fine... Dreamweaver reports no syntax errors or any other errors, but when I preview the page on my testing server, all I get is an empty page.

The browser is not throwing up and flags, and the server is not reporting any kinds of Syntax or Parsing erros... The page simply will not display any results even though I know the search terms do exists in the columns I am searching.

Can anyone have a look at the code and tell me if you can spot the problem?

Thanks
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
<?php require_once('Connections/portepont.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$varFind_rsResults = "-1";
if (isset($_GET['search'])) {
  $varFind_rsResults = $_GET['search'];
}
mysql_select_db($database_portepont, $portepont);
$query_rsResults = sprintf("SELECT * FROM pages WHERE `title` LIKE '%s' OR 'subtitle' LIKE '%s' OR 'content' LIKE '%s' OR 'quote' LIKE '%s' OR 'speaker' LIKE '%s' ORDER BY ID ASC", GetSQLValueString("%" . $varFind_rsResults . "%", "int"),GetSQLValueString("%" . $varFind_rsResults . "%", "int"),GetSQLValueString("%" . $varFind_rsResults . "%", "int"),GetSQLValueString("%" . $varFind_rsResults . "%", "int"),GetSQLValueString("%" . $varFind_rsResults . "%", "int"));
$rsResults = mysql_query($query_rsResults, $portepont) or die(mysql_error());
$row_rsResults = mysql_fetch_assoc($rsResults);
$totalRows_rsResults = mysql_num_rows($rsResults);
?>

Answer : Search page not returning results in PHP MySQL

>> Anyway...I made the changes but now it only returns the last record in the database, regardless of the search
>> parameter...

Getting better.  It's returning SOMETHING :)

Another good troubleshooting technique is to echo the mysql query so you can see if the syntax is breaking.  Add the following PHP somewhere in the body of the page:

<?php echo $query_rsResults; ?>


Random Solutions  
 
programming4us programming4us