TheCut
02-04-2003, 12:50 AM
Hi everyone,
I'm trying to create the search engine for my project, but I'm getting into some problem with this script, hoping that everyone in here can help me. When I run this script I got the following error display. Thank a lot.
"Warning: mysql_fetch_assoc(): 2 is not a valid MySQL result resource in c:\program files\apache group\apache\htdocs\hotel_sample\search.php on line 100"
<?php require_once('../Connections/hotelsample.php'); ?>
<?php
if($HTTP_POST_VARS["bed_option"] == "less")
{
$bComp = "<";
}
else if($HTTP_POST_VARS["bed_option"] == "more")
{
$bComp =">";
}
else
{
$bComp ="=";
}
?>
<?php
if($HTTP_POST_VARS["price_option"] == "above")
{
$pComp = ">";
}
else
{
$pComp = "<=";
}
?>
<?php
$MM_pComp_rsSearch = "<=";
if (isset($pComp)) {
$MM_pComp_rsSearch = (get_magic_quotes_gpc()) ? $pComp : addslashes($pComp);
}
$MM_pNum_rsSearch = "0";
if (isset($HTTP_POST_VARS["price"])) {
$MM_pNum_rsSearch = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS["price"] : addslashes($HTTP_POST_VARS["price"]);
}
$MM_bedComp_rsSearch = "<";
if (isset($bComp)) {
$MM_bedComp_rsSearch = (get_magic_quotes_gpc()) ? $bComp : addslashes($bComp);
}
$MM_bedNum_rsSearch = "0";
if (isset($HTTP_POST_VARS["bed"])) {
$MM_bedNum_rsSearch = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS["bed"] : addslashes($HTTP_POST_VARS["bed"]);
}
mysql_select_db($database_hotelsample, $hotelsample);
$query_rsSearch = sprintf("SELECT ID, price, bed, description, number FROM room WHERE bed %s %s AND price %s %s", $MM_bedComp_rsSearch,$MM_bedNum_rsSearch,$MM_pComp_rsSearch,$MM_pNum_rsSearch);
$rsSearch = mysql_query($query_rsSearch, $hotelsample) or die(mysql_error());
$row_rsSearch = mysql_fetch_assoc($rsSearch);
$totalRows_rsSearch = mysql_num_rows($rsSearch);
?>
<form name="form1" method="post" action="search.php">
<table width="400" border="2" align="center" bordercolor="#0000FF">
<tr align="center">
<td colspan="3">Search for a room</td>
</tr>
<tr>
<td width="130" align="right">Number of beds :</td>
<td width="87"><select name="bed_option" id="bed_option">
<option value="more" selected>More than</option>
<option value="less">Less than</option>
<option value="equal">Equal to</option>
</select></td>
<td width="159">
<input name="bed" type="text" id="bed" size="2"
maxlength="2">bed(s)</td>
</tr>
<tr>
<td align="right">Price Range :</td>
<td><select name="price_option" id="price_option">
<option value="above" selected>Above</option>
<option value="below">Below</option>
</select></td>
<td>$<input name="price" type="text" id="price" size="5"
maxlength="5"></td>
</tr>
<tr>
<td align="right"> </td>
<td colspan="2" align="center"><input type="submit" name="Submit" value="Search">
</td>
</tr>
</table>
</form>
<?php
mysql_free_result($rsSearch);
?>
<table width="83%" border="2" align="center" bordercolor="#0000FF">
<tr>
<td width="8%"><h4>ID</h4></td>
<td width="14%"><h4>Price</h4></td>
<td width="9%"><h4>Bed</h4></td>
<td width="51%"><h4>Description</h4></td>
<td width="18%"><h4>Number</h4></td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_rsSearch['ID']; ?></td>
<td><?php echo $row_rsSearch['price']; ?></td>
<td><?php echo $row_rsSearch['bed']; ?></td>
<td><?php echo $row_rsSearch['description']; ?></td>
<td><?php echo $row_rsSearch['number']; ?></td>
</tr>
<?php } while ($row_rsSearch = mysql_fetch_assoc($rsSearch)); ?>
</table>
I'm trying to create the search engine for my project, but I'm getting into some problem with this script, hoping that everyone in here can help me. When I run this script I got the following error display. Thank a lot.
"Warning: mysql_fetch_assoc(): 2 is not a valid MySQL result resource in c:\program files\apache group\apache\htdocs\hotel_sample\search.php on line 100"
<?php require_once('../Connections/hotelsample.php'); ?>
<?php
if($HTTP_POST_VARS["bed_option"] == "less")
{
$bComp = "<";
}
else if($HTTP_POST_VARS["bed_option"] == "more")
{
$bComp =">";
}
else
{
$bComp ="=";
}
?>
<?php
if($HTTP_POST_VARS["price_option"] == "above")
{
$pComp = ">";
}
else
{
$pComp = "<=";
}
?>
<?php
$MM_pComp_rsSearch = "<=";
if (isset($pComp)) {
$MM_pComp_rsSearch = (get_magic_quotes_gpc()) ? $pComp : addslashes($pComp);
}
$MM_pNum_rsSearch = "0";
if (isset($HTTP_POST_VARS["price"])) {
$MM_pNum_rsSearch = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS["price"] : addslashes($HTTP_POST_VARS["price"]);
}
$MM_bedComp_rsSearch = "<";
if (isset($bComp)) {
$MM_bedComp_rsSearch = (get_magic_quotes_gpc()) ? $bComp : addslashes($bComp);
}
$MM_bedNum_rsSearch = "0";
if (isset($HTTP_POST_VARS["bed"])) {
$MM_bedNum_rsSearch = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS["bed"] : addslashes($HTTP_POST_VARS["bed"]);
}
mysql_select_db($database_hotelsample, $hotelsample);
$query_rsSearch = sprintf("SELECT ID, price, bed, description, number FROM room WHERE bed %s %s AND price %s %s", $MM_bedComp_rsSearch,$MM_bedNum_rsSearch,$MM_pComp_rsSearch,$MM_pNum_rsSearch);
$rsSearch = mysql_query($query_rsSearch, $hotelsample) or die(mysql_error());
$row_rsSearch = mysql_fetch_assoc($rsSearch);
$totalRows_rsSearch = mysql_num_rows($rsSearch);
?>
<form name="form1" method="post" action="search.php">
<table width="400" border="2" align="center" bordercolor="#0000FF">
<tr align="center">
<td colspan="3">Search for a room</td>
</tr>
<tr>
<td width="130" align="right">Number of beds :</td>
<td width="87"><select name="bed_option" id="bed_option">
<option value="more" selected>More than</option>
<option value="less">Less than</option>
<option value="equal">Equal to</option>
</select></td>
<td width="159">
<input name="bed" type="text" id="bed" size="2"
maxlength="2">bed(s)</td>
</tr>
<tr>
<td align="right">Price Range :</td>
<td><select name="price_option" id="price_option">
<option value="above" selected>Above</option>
<option value="below">Below</option>
</select></td>
<td>$<input name="price" type="text" id="price" size="5"
maxlength="5"></td>
</tr>
<tr>
<td align="right"> </td>
<td colspan="2" align="center"><input type="submit" name="Submit" value="Search">
</td>
</tr>
</table>
</form>
<?php
mysql_free_result($rsSearch);
?>
<table width="83%" border="2" align="center" bordercolor="#0000FF">
<tr>
<td width="8%"><h4>ID</h4></td>
<td width="14%"><h4>Price</h4></td>
<td width="9%"><h4>Bed</h4></td>
<td width="51%"><h4>Description</h4></td>
<td width="18%"><h4>Number</h4></td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_rsSearch['ID']; ?></td>
<td><?php echo $row_rsSearch['price']; ?></td>
<td><?php echo $row_rsSearch['bed']; ?></td>
<td><?php echo $row_rsSearch['description']; ?></td>
<td><?php echo $row_rsSearch['number']; ?></td>
</tr>
<?php } while ($row_rsSearch = mysql_fetch_assoc($rsSearch)); ?>
</table>