•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 397,851 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,322 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 10679 | Replies: 2
![]() |
•
•
Join Date: Aug 2004
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
Hi Everyone
I am working through a book called Dreamweaver PHP Web Development. It has a tutorial for creating a booking system for a hotel. The because went out of publication in 2002 and there isn't a errata on the Glasshaus site for it . When creating the search page I am getting the following error message. Warning: mysql_fetch_assoc(): 2 is not a valid MySQL result resource. The page is only showing one result and I think that the error message has something to do with that.
The code for the page is as follows
<?php require_once('Connections/conn1.php'); ?>
<?php
if($_POST['bed_option'] == "less")
{
$bcomp = "<";
}
else if($_POST["bed_option"] == "more")
{
$bComp = ">";
}
else
{
$bComp = "=";
}
?>
<?php
if($_POST["price_option"] == "above")
{
$pComp = ">";
}
else
{
$pComp = "<=";
}
?>
<?php
$bedComp_rsSearch = "<";
if (isset($bComp)) {
$bedComp_rsSearch = (get_magic_quotes_gpc()) ? $bComp : addslashes($bComp);
}
$bedNum_rsSearch = "0";
if (isset($_POST['bed'])) {
$bedNum_rsSearch = (get_magic_quotes_gpc()) ? $_POST['bed'] : addslashes($_POST['bed']);
}
$pComp_rsSearch = "<=";
if (isset($pComp)) {
$pComp_rsSearch = (get_magic_quotes_gpc()) ? $pComp : addslashes($pComp);
}
$pNum_rsSearch = "0";
if (isset($_POST['price'])) {
$pNum_rsSearch = (get_magic_quotes_gpc()) ? $_POST['price'] : addslashes($_POST['price']);
}
mysql_select_db($database_conn1, $conn1);
$query_rsSearch = sprintf("SELECT ID, price, bed, number FROM room WHERE bed %s %s AND price %s %s", $bedComp_rsSearch,$bedNum_rsSearch,$pComp_rsSearch,$pNum_rsSearch);
$rsSearch = mysql_query($query_rsSearch, $conn1) 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="0">
<tr align="center">
<td colspan="3">Search for a room</td>
</tr>
<tr>
<td width="152" align="right">Number of beds :</td>
<td width="38"><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="196">
<input name="bed" type="text" id="bed" value="1" 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" value="25" 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="50%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> </font></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Price</font></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Bed</font></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Room Number</font></td>
</tr>
<?php do { ?>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> <?php echo $row_rsSearch['ID']; ?></font></td>
<td><?php echo $row_rsSearch['price']; ?></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> <?php echo $row_rsSearch['bed']; ?></font></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> <?php echo $row_rsSearch['number']; ?></font></td>
</tr>
<?php } while ($row_rsSearch = mysql_fetch_assoc($rsSearch)); ?>
</table>
<p> </p>
The error message says line 100 which is in the bold part of the code. Hope someone can explain what the error message means and how to fix it.
Thanks Lynne
I am working through a book called Dreamweaver PHP Web Development. It has a tutorial for creating a booking system for a hotel. The because went out of publication in 2002 and there isn't a errata on the Glasshaus site for it . When creating the search page I am getting the following error message. Warning: mysql_fetch_assoc(): 2 is not a valid MySQL result resource. The page is only showing one result and I think that the error message has something to do with that.
The code for the page is as follows
<?php require_once('Connections/conn1.php'); ?>
<?php
if($_POST['bed_option'] == "less")
{
$bcomp = "<";
}
else if($_POST["bed_option"] == "more")
{
$bComp = ">";
}
else
{
$bComp = "=";
}
?>
<?php
if($_POST["price_option"] == "above")
{
$pComp = ">";
}
else
{
$pComp = "<=";
}
?>
<?php
$bedComp_rsSearch = "<";
if (isset($bComp)) {
$bedComp_rsSearch = (get_magic_quotes_gpc()) ? $bComp : addslashes($bComp);
}
$bedNum_rsSearch = "0";
if (isset($_POST['bed'])) {
$bedNum_rsSearch = (get_magic_quotes_gpc()) ? $_POST['bed'] : addslashes($_POST['bed']);
}
$pComp_rsSearch = "<=";
if (isset($pComp)) {
$pComp_rsSearch = (get_magic_quotes_gpc()) ? $pComp : addslashes($pComp);
}
$pNum_rsSearch = "0";
if (isset($_POST['price'])) {
$pNum_rsSearch = (get_magic_quotes_gpc()) ? $_POST['price'] : addslashes($_POST['price']);
}
mysql_select_db($database_conn1, $conn1);
$query_rsSearch = sprintf("SELECT ID, price, bed, number FROM room WHERE bed %s %s AND price %s %s", $bedComp_rsSearch,$bedNum_rsSearch,$pComp_rsSearch,$pNum_rsSearch);
$rsSearch = mysql_query($query_rsSearch, $conn1) 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="0">
<tr align="center">
<td colspan="3">Search for a room</td>
</tr>
<tr>
<td width="152" align="right">Number of beds :</td>
<td width="38"><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="196">
<input name="bed" type="text" id="bed" value="1" 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" value="25" 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="50%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> </font></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Price</font></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Bed</font></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Room Number</font></td>
</tr>
<?php do { ?>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> <?php echo $row_rsSearch['ID']; ?></font></td>
<td><?php echo $row_rsSearch['price']; ?></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> <?php echo $row_rsSearch['bed']; ?></font></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> <?php echo $row_rsSearch['number']; ?></font></td>
</tr>
<?php } while ($row_rsSearch = mysql_fetch_assoc($rsSearch)); ?>
</table>
<p> </p>
The error message says line 100 which is in the bold part of the code. Hope someone can explain what the error message means and how to fix it.
Thanks Lynne
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
Similar Threads
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource (PHP)
- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource (PHP)
- Supplied argument is not a valid MySQL result resource (MySQL)
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource (PHP)
- while function and "mysql_fetch_assoc() not a valid MySQL result resource" (PHP)
Other Threads in the PHP Forum
- Previous Thread: Fread + Ssl
- Next Thread: I think this is a php problem?


before your troubleing code
Linear Mode