Jump to content

[SOLVED] mysql_fetch_array() warning, but code is retrieving data???


creapeaucreations

Recommended Posts

I have a link that passes the "list_id" variable to another page. The page receiving the variable then searches "listing" table to get record. It works, and displays the data, but I also get the following error printed on the screen too:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\adr\admin\listings\edit-listing.php on line 21. I CANNOT GET RID OF THE ERROR? I have this same set up on another page, instead using brokers table and broker_id and there are no problems. ANY IDEAS??

 

line 19        include ("../../addphp/connect.php"); //connects to database

line 20        $query = mysql_query("SELECT * FROM listings WHERE list_id =".$_REQUEST['list_id'])or die ('Error: '.mysql_error ());

line 21        while ($row = mysql_fetch_array($query)) { ?>

 

 

I have tried the following, but end with the same results:

line 20        $query = mysql_query("SELECT * FROM listings WHERE list_id =".$_REQUEST['list_id']."")or die ('Error: '.mysql_error ());

line 20        $query = mysql_query("SELECT * FROM listings WHERE list_id =' ".$_REQUEST['list_id']." ' ")or die ('Error: '.mysql_error ());

 

$list = $_REQUEST['list_id'];

line 20        $query = mysql_query("SELECT * FROM listings WHERE list_id =' $list ' ")or die ('Error: '.mysql_error ());

 

The line calling the page is:

<a href="/adr/admin/listings/edit-listing.php?list_id=<?php echo $row['list_id'] ?>">Edit</a>

*note the value of $row['list_id'] is 1380 (an int)

 

Page it calls (edit-listing.php)...

<html>

<head></head>

<body id="admin">

<div id="wrapper">

<div id="header"></div>

  <div id="navigation">

  <?php include "../../addphp/navigation.php"; ?>

  </div>

<div id="displaywrapper">

    <form action="process.php" method="post">

    <table id="editlisting">

<?php

include ("../../addphp/connect.php");

$query = mysql_query("SELECT * FROM listings WHERE list_id='".$_REQUEST['list_id']."'");

while ($row = mysql_fetch_array($query)) { ?>  ******THIS IS THE ERROR LINE ************

        <tr>

          <td width="108">Listing ID:</td>

          <td width="189"><input name="list_id" type="text" maxlength="4" value="<?php echo $row['list_id'] ?>" /></td>

          <td width="244"></td>

        </tr>

        <tr>

          <td>MLS No.:</td>

          <td><input name="mls" type="text" maxlength="8" value="<?php echo $row['mls'] ?>"/></td>

          <td></td>

        </tr>

        <tr>

          <td>Brooker ID:</td>

          <td><select class="selectwidth" name="broker_id" size="1" width="240px">

          <?php

$query = "SELECT * FROM brokers ORDER BY broker_id";

$sql = mysql_query($query)or die("Failded to select Brokers table");

while ($get = mysql_fetch_array($sql)) {    ***** THIS ONE CAUSES NO ERROR ******

?>

            <option

            <?php if ($row['broker_id'] == $get['broker_id']) { echo " selected='selected' "; } ?>

            value="<?php echo $get['broker_id']; ?>"><?php echo $get['broker_id']; ?> - <?php echo $get['firstname']; ?> <?php echo $get['lastname']; ?></option>

<?php } ?>

          </select></td>

          <td></td>

        </tr>

        <tr>

          <td>Property Type:</td>

          <td>

          <select class="selectwidth" name="prop_type" size="1" width="240px">

            <option <?php if ($row['prop_type'] == 'Single Family') { echo " selected='selected' "; } ?> width="300px" value"Single Family">Single Family</option>

            <option <?php if ($row['prop_type'] == 'Multi-Family') { echo " selected='selected' "; } ?>value"Multi-Family">Multi-Family</option>

            <option <?php if ($row['prop_type'] == 'Waterfront') { echo " selected='selected' "; } ?>value"Waterfront">Waterfront</option>

            <option <?php if ($row['prop_type'] == 'Commercial') { echo " selected='selected' "; } ?>value"Commercial">Commercial</option>

            <option <?php if ($row['prop_type'] == 'Vacant Lot') { echo " selected='selected' "; } ?>value"Vacant Lot">Vacant Lot</option>

            <option <?php if ($row['prop_type'] == 'Rental') { echo " selected='selected' "; } ?>value"Rental">Rental</option>

            </select>

          </td>

          <td></td>

        </tr>

        <tr>

          <td>Price:</td>

          <td colspan="2"><input name="price" type="text" value="<?php echo $row['price'] ?>" /><em>(Price with no coma's or decimal)</em></td>

        </tr>

        <tr>

          <td>Address:</td>

          <td colspan="2"><input name="address" type="text" value="<?php echo $row['address'] ?>" /><em>(Street address)</em></td>

        </tr>

        <tr>

          <td>City:</td>

          <td><input name="city" type="text" value="<?php echo $row['city'] ?>" /></td>

          <td></td>

        </tr>

        <tr>

          <td>State:</td>

          <td><input name="state" type="text" value="<?php echo $row['state'] ?>" /></td>

          <td></td>

        </tr>

        <tr>

          <td>Zip:</td>

          <td><input name="zip" type="text" value="<?php echo $row['zip'] ?>" /></td>

          <td></td>

        </tr>

        <tr>

          <td>Title:</td>

          <td><input name="title" type="text" value="<?php echo $row['title'] ?>" /></td>

          <td></td>

        </tr>

        <tr>

          <td colspan="3">Description:</td>

        </tr>

        <tr>

          <td colspan="2"><textarea name="description" cols="45" rows="10" ><?php echo $row['description'] ?></textarea></td>

          <td></td>

        </tr>

        <tr>

          <td>Bedrooms:</td>

          <td colspan="2"><input name="bedrooms" type="text" value="<?php echo $row['bedrooms'] ?>" /><em>(Enter in decimal form e.g. 2.0 or 3.5)</em></td>

        </tr>

        <tr>

          <td>Bathrooms:</td>

          <td colspan="2"><input name="bathrooms" type="text" value="<?php echo $row['bathrooms'] ?>" /><em>(Enter in decimal form e.g. 2.0 or 3.5)</em></td>

        </tr>

        <tr>

          <td>Family Room:</td>

          <td><input name="family_room" type="text" value="<?php echo $row['family_room'] ?>" /></td>

          <td></td>

        </tr>

        <tr>

          <td>Den/Office:</td>

          <td><input name="den_office" type="text" value="<?php echo $row['den_office'] ?>"  /></td>

          <td></td>

        </tr>

        <tr>

          <td>Stories:</td>

          <td colspan="2"><input name="stories" type="text" value="<?php echo $row['stories'] ?>" /><em>(Enter in decimal form e.g. 2.0 or 3.5)</em></td>

        </tr>

        <tr>

          <td>Sq. Feet:</td>

          <td colspan="2"><input name="sq_ft" type="text" value="<?php echo $row['sq_ft'] ?>" /><em>(Feet with no comma's or decimal)</em></td>

        </tr>

        <tr>

          <td>Lot Size:</td>

          <td><input name="lot_size" type="text" value="<?php echo $row['lot_size'] ?>"  /></td>

          <td></td>

        </tr>

        <tr>

          <td>Basement:</td>

          <td><input name="basement" type="text" value="<?php echo $row['basement'] ?>"  /></td>

          <td></td>

        </tr>

        <tr>

          <td>Garage:</td>

          <td><input name="garage" type="text" value="<?php echo $row['garage'] ?>"  /></td>

          <td></td>

        </tr>

        <tr>

        <td></td>

          <td><input name="add" type="submit" value="Add Listing" /></td>

          <td></td>

        </tr>

      <?php } ?>

</table>

</form>

  </div>

  <div id="footer">

  <?php include "../../addphp/footer.php"; ?>

  </div>

</div><!--wrapper-->

</body>

</html>

 

the problem is that you redefine $query inside the while loop

 

while ($row = mysql_fetch_array($query)) {

 

it does okay on the first mysql_fetch_array, but you redefine $query in the loop, so it fails after the first one.

 

change one of the variable names.

 

this update should fix it:

 

               $query2 = "SELECT * FROM brokers ORDER BY broker_id";
               $sql = mysql_query($query2)or die("Failded to select Brokers table");
               while ($get = mysql_fetch_array($sql)) {

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.