5 Replies Latest reply on Sep 7, 2009 11:57 PM by Nit3watch

    php site search displays no results

    Nit3watch

      Hi I followed this tut, http://www.pixeldigest.com/phpsearch.html

       

      There are 2 pages, the search page with text box and submit button, and the results page. When clicking on the submit button, it takes you to the search result page but no data is displayed :< My database is connected and everything, also when adding the recordset the 'test' works and displays the results.

       

      If some1 could help would be great.

      Thanks

       

      Here's the code:

       

      Search page:

       

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>search</title>
      </head>

       

      <body>
      <form id="fmsearch" name="fmsearch" method="get" action="search_result.php">
        <label for="search">search</label>
        <input type="text" name="search" id="search" />
        <label for="submit">submit</label>
        <input type="submit" name="submit" id="submit" value="Submit" />
      </form>
      </body>
      </html>

       

      Result page:

       

      <?php require_once('Connections/search_db.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;
      }
      }

       

      $maxRows_Recordset1 = 10;
      $pageNum_Recordset1 = 0;
      if (isset($_GET['pageNum_Recordset1'])) {
        $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
      }
      $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

       

      $colname_Recordset1 = "-1";
      if (isset($_GET['name'])) {
        $colname_Recordset1 = $_GET['name'];
      }
      mysql_select_db($database_search_db, $search_db);
      $query_Recordset1 = sprintf("SELECT * FROM resturants WHERE name = %s", GetSQLValueString($colname_Recordset1, "text"));
      $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
      $Recordset1 = mysql_query($query_limit_Recordset1, $search_db) or die(mysql_error());
      $row_Recordset1 = mysql_fetch_assoc($Recordset1);

       

      if (isset($_GET['totalRows_Recordset1'])) {
        $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
      } else {
        $all_Recordset1 = mysql_query($query_Recordset1);
        $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
      }
      $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
      ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>search result</title>
      </head>

       

      <body>
      <?php do { ?>
        <table width="636" border="1" cellspacing="0" cellpadding="0">
          <tr>
            <th height="289" scope="col"><?php echo $row_Recordset1['id']; ?><?php echo $row_Recordset1['name']; ?><br />      <?php echo $row_Recordset1['location']; ?><br /></th>
          </tr>
        </table>
        <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
      </body>
      </html>
      <?php
      mysql_free_result($Recordset1);
      ?>