PDA

View Full Version : PHP search form


olm75
08-09-2005, 06:57 AM
ok, for some reason the form is not querying all the variables..from the search page..i want the viewer to be able to search the MySQL database by 1 or any of the search fields on the form....ex of the form at nightspotz.com ('http://www.nightspotz.com/testsearch.php') ...... here is the code for the results page:


<?php require_once('../Connections/connNightspotz.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];

$maxRows_rsSRCH = 10;
$pageNum_rsSRCH = 0;
if (isset($_GET['pageNum_rsSRCH'])) {
$pageNum_rsSRCH = $_GET['pageNum_rsSRCH'];
}
$startRow_rsSRCH = $pageNum_rsSRCH * $maxRows_rsSRCH;

$AC_rsSRCH = "1";
if (isset($_POST['areacode'])) {
$AC_rsSRCH = (get_magic_quotes_gpc()) ? $_POST['areacode'] : addslashes($_POST['areacode']);
}
$VN_rsSRCH = "2";
if (isset($_POST['venuename'])) {
$VN_rsSRCH = (get_magic_quotes_gpc()) ? $_POST['venuename'] : addslashes($_POST['venuename']);
}
$VT_rsSRCH = "3";
if (isset($_POST['venuetype'])) {
$VT_rsSRCH = (get_magic_quotes_gpc()) ? $_POST['venuetype'] : addslashes($_POST['venuetype']);
}
$AG_rsSRCH = "4";
if (isset($_POST['agegroup'])) {
$AG_rsSRCH = (get_magic_quotes_gpc()) ? $_POST['agegroup'] : addslashes($_POST['agegroup']);
}
$MT_rsSRCH = "5";
if (isset($_POST['musictype'])) {
$MT_rsSRCH = (get_magic_quotes_gpc()) ? $_POST['musictype'] : addslashes($_POST['musictype']);
}
mysql_select_db($database_connNightspotz, $connNightspotz);
$query_rsSRCH = sprintf("SELECT * FROM venues WHERE venuename LIKE '%s%%' OR areacode = '%s' OR venuetype = '%s' OR agegroup = '%s' OR musictype = '%s' ORDER BY venuename DESC", $VN_rsSRCH,$AC_rsSRCH,$VT_rsSRCH,$AG_rsSRCH,$M T_rs

SRCH);
$query_limit_rsSRCH = sprintf("%s LIMIT %d, %d", $query_rsSRCH, $startRow_rsSRCH, $maxRows_rsSRCH);
$rsSRCH = mysql_query($query_limit_rsSRCH, $connNightspotz) or die(mysql_error());
$row_rsSRCH = mysql_fetch_assoc($rsSRCH);

if (isset($_GET['totalRows_rsSRCH'])) {
$totalRows_rsSRCH = $_GET['totalRows_rsSRCH'];
} else {
$all_rsSRCH = mysql_query($query_rsSRCH);
$totalRows_rsSRCH = mysql_num_rows($all_rsSRCH);
}
$totalPages_rsSRCH = ceil($totalRows_rsSRCH/$maxRows_rsSRCH)-1;

$queryString_rsSRCH = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rsSRCH") == false &&
stristr($param, "totalRows_rsSRCH") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rsSRCH = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_rsSRCH = sprintf("&totalRows_rsSRCH=%d%s", $totalRows_rsSRCH, $queryString_rsSRCH);

$queryString_rsSrch = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rsSrch") == false &&
stristr($param, "totalRows_rsSrch") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rsSrch = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_rsSrch = sprintf("&totalRows_rsSrch=%d%s", $totalRows_rsSrch, $queryString_rsSrch);
?>
<?php
$query_venues = "DELETE FROM venue";
mysql_query($query_venue,$srch);
?>

davidj
09-16-2005, 09:37 AM
try echo - ing your $query_rsSRCH

then search again

copy the echo'd SQL Query from the screen and paste it into your DB script manager/console. Execute the script and see if you get something back (results)

let me know the outcome of this test