Skip to main content
Participating Frequently
September 8, 2009
Question

search results page url?

  • September 8, 2009
  • 1 reply
  • 1411 views

If I have a form, containing text field, (for the search parameters.) and a submit button, (set to POST, and action: being my results page, running a recordset query[on the results page].).

if the form is run, should the URL look this simple?

http://localhost/search.php

to

after posting, (running the query.): http://localhost/search_results.php

After battling with this for about a week, all it looks like is the form is simply just taking me to the results page and NOT performing an action, (no results/records are displayed)?

This topic has been closed for replies.

1 reply

David_Powers
Inspiring
September 8, 2009

Moved to the Dreamweaver Application Development forum, which deals with server-side issues.

Normally, search forms use the GET method, which passes the variables as a query string appended to the end of the URL. Regardless of whether you use GET or POST, you need to use the appropriate $_GET or $_POST superglobal array to retrieve the values of the variables to insert into the SQL that performs the search. If nothing is happening, you are probably using the wrong superglobal array.

Nit3watchAuthor
Participating Frequently
September 8, 2009

Im getting highly fustrated, I followed "Building search and results pages" from the Adobe help section,

http://help.adobe.com/en_US/Dreamweaver/10.0_Using/WScbb6b82af5544594822510a94ae8d65-78b0a.html

I do as it says, but I still get no results on my results page, after trying all funny things...

This is what Ive done:

on search page:

Insert form, in form; added text field and a button.

     form Method: POST

     form Action: search_results.php

          button Action: Submit form, (this is default.)

on results page:

attached recordset:

And then inserted a dynamic table.

Should I be doing more, am I not telling the page to retrieve anything?

Here's the code of the results page:

<?php require_once('Connections/search.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($_POST['name'])) {
  $colname_Recordset1 = $_POST['name'];
}
mysql_select_db($database_search, $search);
$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) 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>Untitled Document</title>
</head>

<body>
<table border="1">
  <tr>
    <td>id</td>
    <td>name</td>
    <td>location</td>
    <td>address</td>
    <td>food</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_Recordset1['id']; ?></td>
      <td><?php echo $row_Recordset1['name']; ?></td>
      <td><?php echo $row_Recordset1['location']; ?></td>
      <td><?php echo $row_Recordset1['address']; ?></td>
      <td><?php echo $row_Recordset1['food']; ?></td>
    </tr>
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

David_Powers
Inspiring
September 8, 2009

The main problem lies in your search form. The text input field looks like this:

<input type="text" name="Name" id="Name" />

Your recordset filter is looking for "name". "Name" and "name" are not the same. PHP is case-sensitive.

The other problem is that you have also called the form "name" - this time with a lowercase n:

<form id="name" name="name" method="post" action="search_results.php">

Because names and IDs are case-sensitive, the form name and the field name are seen as being different, but it's a recipe for confusion.

Change the form by giving it a different name and ID, and use lowercase for "name" in the text input field like this:

<form id="search" name="search" method="post" action="search_results.php">
  <label for="textinput">textinput</label>
  <input type="text" name="name" id="name" />
  <label for="submittext">submit</label>
  <input type="submit" name="submittext" id="submittext" value="Submit" />
</form>