Jump to content

mysql_fetch_array() expects parameter 1 to be resource, boolean given


Richard Yates

Recommended Posts

I have a local php test server on my computer and I also upload to a web site server. Everything works fine on both servers except: I wrote a small utility to process mysql query strings. It works fine on the web site server. On the local server, SELECT queries run fine. UPDATE and INSERT give the above error. These exact same queries work fine in the same php script on the web server and they work fine in the phpMyAdmin SQL query utility on the local server. They fail only on the local server with the php script.

 

The relevant script is:

 

if (isset($_GET['searchget'])) { $search = $_GET['searchget']; }

mysql_select_db($database_Salem_Harvest, $Salem_Harvest);

$search=stripslashes($search);

$rsSearch = mysql_query($search, $Salem_Harvest) or die(mysql_error());

$row_rsSearch = mysql_fetch_array($rsSearch, MYSQL_BOTH) or die(mysql_error());

 

The last line is the one that dies. $search echoes out correctly.

Link to comment
Share on other sites

"Are you sure that is actually the code that's being executed? The error would tend to indicate that the query failed, therefore it should trigger the first die() clause and echo a MySQL error, not a php error."

 

thanks for the reply. Yes, I am sure. The same form works when a SELECT string is input. If I insert an 'exit;' after the stripslash line it prints the string correctly and stops. Checking further, i see in the database that the UPDATE query DOES change the data in the record correctly. Something else must happen when I am trying to print the records that are changed. The full code (leaving out some irrelevant html) is:

 

<?php require_once('../Connections/Salem_Harvest.php');
$search = "SELECT * FROM pickers WHERE ID_picker = 1";
if (isset($_GET['searchget'])) { $search = $_GET['searchget']; }
mysql_select_db($database_Salem_Harvest, $Salem_Harvest);
$search=stripslashes($search);
$rsSearch = mysql_query($search, $Salem_Harvest) or die(mysql_error());
$row_rsSearch = mysql_fetch_array($rsSearch, MYSQL_BOTH) or die(mysql_error());
$keys = array_keys ($row_rsSearch);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SQL</title>
</head>

<body class="SH">
<div id="container">
<div id="mainContent">
    <h2><strong>SQL search utility</strong></h2>

      <form id="search" name="search" method="get" action="SQL2.php">
      Type SQL String and press 'Enter'
      <input name="searchget" type="text" id="searchget" value="<?php echo $search ?>" size="300" maxlength="300" />
      </form>
    <p> </p>
    <table width="1220" border="1" cellpadding="2" cellspacing="2" id="rsearchresults">
      <tr><?php for($i=1;$i<count($keys);$i=$i+2) { ?>
        <th><?php echo $keys[$i];?></td> <?php } ?> </th>
      <?php do { ?>
      <tr><?php for($i=0;$i<(count($row_rsSearch)/2);$i++) { ?>
           <td><?php echo $row_rsSearch[$i];?></td> <?php } ?>
      </tr>
        <?php } while ($row_rsSearch = mysql_fetch_array($rsSearch, MYSQL_BOTH)); ?>     
    </table>
    </div>
  <br class="clearfloat" />
</div>
</body>
</html>
<?php mysql_free_result($rsSearch); ?>

 

MOD EDIT: code tags added.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.