PDA

View Full Version : Search a datatbase from a search box


Boggie
05-02-2005, 01:38 AM
Hi, i have 3 pages set up on my webpage.

1. Insert record page
2. Search database page
3. Results page

All my entry page fields work just fine. The problem is when i go to my search page and enter data, it just goes to the results page. It's suppose to get the data from the search field and filter the results in the database, and display it on the results.php.

Search page:
<?php require_once('Connections/rproject.php'); ?>
<?php
$colname_Recordset1 = "1";
if (isset($HTTP_POST_VARS['textfield'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS['textfield'] : addslashes($HTTP_POST_VARS['textfield']);
}
mysql_select_db($database_rproject, $rproject);
$query_Recordset1 = sprintf("SELECT * FROM rp_users WHERE rp_eventlocation = '%s'", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $rproject) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$currentPage = $HTTP_SERVER_VARS["PHP_SELF"];

$queryString_raidsearch = "";
if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
$params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_raidsearch") == false &&
stristr($param, "totalRows_raidsearch") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_raidsearch = "&" . implode("&", $newParams);
}
}
$queryString_raidsearch = sprintf("&totalRows_raidsearch=%d%s", $totalRows_raidsearch, $queryString_raidsearch);
?>




<html>
<head>
<title>Raid Project Search by Whoaguild.com</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<p><strong><font size="6"><em>Raid Project Event Search Form</em></font></strong><em><font color="#FF0000">beta
</font></em></p>
<p></p>
<form action="raidresults.php" method="post" name="raidsearch" id="raidsearch">
<table width="100%" border="0">
<tr>
<td width="16%">Event Location: </td>
<td width="84%"> <input name="textfield" type="text" value="<?php echo $row_Recordset1['rp_eventlocation']; ?>"></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td> <input type="submit" name="Submit" value="Search"></td>
<td> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
</form>
<p></p>
<p> </p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>



Results page:

<?php require_once('Connections/rproject.php'); ?>
<?php
mysql_select_db($database_rproject, $rproject);
$query_Recordset1 = "SELECT * FROM rp_users";
$Recordset1 = mysql_query($query_Recordset1, $rproject) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$currentPage = $HTTP_SERVER_VARS["PHP_SELF"];

$queryString_eventlocationresults = "";
if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
$params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_eventlocationresults") == false &&
stristr($param, "totalRows_eventlocationresults") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_eventlocationresults = "&" . implode("&", $newParams);
}
}
$queryString_eventlocationresults = sprintf("&totalRows_eventlocationresults=%d%s", $totalRows_eventlocationresults, $queryString_eventlocationresults);
?>






<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<p><strong><font size="6"><em>Raid Project Event Results Page</em></font></strong><em><font color="#FF0000">beta</font></em>
</p>
<center>
<table width="100%" border="0">
<tr>
<td>Name</td>
<td>Server</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['rp_name']; ?></td>
<td><?php echo $row_Recordset1['rp_server']; ?></td>
</tr>
<?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?>
</table>
</center>
<p></p>

</body>
</html>
<?php
mysql_free_result($Recordset1);
?>



Currently the search page is limited to searching for only the Event Location

Later i will add a search for: Guild name, Event time

I am using Dreamweaver MX

Thanks in advanced