Get ready for BLACK FRIDAY shopping starting in

Forums

PHP

This topic is locked

Multiple Search Fields

Posted 13 Sep 2007 18:03:38
1
has voted
13 Sep 2007 18:03:38 EriK Miller posted:
I'm attempting to do multiple field search on a recordset that hold information about IT Projects. In the .html form the method is post. The results page code is posted below. What am I doing wrong? I can't see any issues. If I change th SQL to use OR instead of AND I get all of the records. Which is certainly NOT what I want. Any help you can provide would be greatly appreciated.

<pre id=code><font face=courier size=2 id=code>
&lt;?php require_once('../Connections/is_request.php'); ?&gt;
&lt;?php
if (!function_exists("GetSQLValueString") {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = ""
{
$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;
}
}

$varMonth_Search = "*";
if (isset($_REQUEST["objectiveGoLiveMonth"])) {
$varMonth_Search = $_REQUEST["objectiveGoLiveMonth"];
}
$varSponsor_Search = "*";
if (isset($_REQUEST["projectSponsor"])) {
$varSponsor_Search = $_REQUEST["projectSponsor"];
}
$varName_Search = "*";
if (isset($_REQUEST["projectName"])) {
$varName_Search = $_REQUEST["projectName"];
}
$varManager_Search = "*";
if (isset($_REQUEST["projectManager"])) {
$varManager_Search = $_REQUEST["projectManager"];
}
$varOwner_Search = "*";
if (isset($_REQUEST["projectOwner"])) {
$varOwner_Search = $_REQUEST["projectOwner"];
}
mysql_select_db($database_is_request, $is_request);
$query_Search = sprintf("SELECT projectID, requestDate, projectName, projectSponsor, projectOwner, projectManager, objectiveGoLiveDay, objectiveGoLiveMonth, objectiveGoLiveYear FROM isproject WHERE isproject.projectName LIKE %s AND isproject.projectSponsor LIKE %s AND isproject.projectOwner LIKE %s AND isproject.projectManager LIKE %s AND isproject.objectiveGoLiveMonth LIKE %s", GetSQLValueString($varName_Search, "text",GetSQLValueString($varSponsor_Search, "text",GetSQLValueString($varOwner_Search, "text",GetSQLValueString($varManager_Search, "text",GetSQLValueString($varMonth_Search, "text");
$Search = mysql_query($query_Search, $is_request) or die(mysql_error());
$row_Search = mysql_fetch_assoc($Search);
$totalRows_Search = mysql_num_rows($Search);
?&gt;&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Search Results&lt;/title&gt;
&lt;style type="text/css"&gt;
&lt;!--
.style1 {font-size: 12px}
--&gt;
&lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;table width="700px" align="center" style="background-image: url(images/sr_tr_background.jpg); padding: 10px; background-repeat: no-repeat; color:#FFFFFF; font-family: Arial, Helvetica, sans-serif;"&gt;
&lt;tr&gt;
&lt;td align="center" width="5%"&gt;ID&lt;/td&gt;
&lt;td align="center" width="15%"&gt;Request Date&lt;/td&gt;
&lt;td align="center" width="30%"&gt;Project Name&lt;/td&gt;
&lt;td align="center" width="15%"&gt;Sponsor&lt;/td&gt;
&lt;td align="center" width="15%"&gt;Owner&lt;/td&gt;
&lt;td align="center" width="10%"&gt;Manager&lt;/td&gt;
&lt;td align="center" width="10%"&gt;Go Live&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;table width="700px" align="center" style="background-image: url(images/sr_list_background.jpg); padding: 10px; background-repeat: no-repeat; color:#000000; font-family: Arial, Helvetica, sans-serif; height: 600px;"&gt;
&lt;tr&gt;
&lt;td align="center" width="5%"&gt;&lt;span class="style1"&gt;&lt;?php echo $row_Search['projectID']; ?&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="center" width="12%" nowrap="nowrap"&gt;&lt;div style="overflow: hidden;"&gt;&lt;?php echo $row_Search['requestDate']; ?&gt;&lt;/div&gt;&lt;/td&gt;
&lt;td align="center" width="30%"&gt;&lt;a class="style1"&gt;&lt;?php echo $row_Search['projectName']; ?&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td align="center" width="15%"&gt;&lt;span class="style1"&gt;&lt;?php echo $row_Search['projectSponsor']; ?&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="center" width="15%"&gt;&lt;span class="style1"&gt;&lt;?php echo $row_Search['projectOwner']; ?&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="center" width="10%"&gt;&lt;span class="style1"&gt;&lt;?php echo $row_Search['projectManager']; ?&gt;&lt;/span&gt;&lt;/td&gt;
&lt;td align="center" width="10%"&gt;&lt;?php echo $row_Search['objectiveGoLiveMonth']; ?&gt; / &lt;?php echo $row_Search['objectiveGoLiveDay']; ?&gt; / &lt;?php echo $row_Search['objectiveGoLiveYear']; ?&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan="7" align="center"&gt;&lt;h3&gt;Sorry your search did not return any results &lt;/h3&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align="center" colspan="7"&gt;&lt;p&gt;&lt;a href="results.php"&gt;View All&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="search.php"&gt;Back to Search&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan="7" style="height: 100%;" align="center"&gt; Previous

&nbsp;

Next &lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;?php
mysql_free_result($Search);
?&gt;
</font id=code></pre id=code>

Reply to this topic