Jump to content

mysql_fetch_array () expect parameter 1 to be resource


diasansley

Recommended Posts

the below is a simple search code.. I have listed the error at the end

 

<div id="searchdiv">
                                 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
                                 <div id="searchdivtext">Info :</div>
                                 <input type="text" name="search"  id="searchdivtextbox">
                                 <input type="submit" id="searchdivbtn" name="submit">
                                 </form>
                          </div>
                          
                          <?php
                                 if (isset($_POST['submit'])) // perform search only if a string was entered. 
                                { 
                                  mysql_connect('localhost','root','') or                                                              
                                  die('Could not connect to mysql ' . mysql_error()); // error message
                                                                 
                                 mysql_select_db("infosite") or die(mysql_error()); 
                                 $query = "select * from wp_usermeta WHERE Name='$search'"; 
                                  $result = mysql_query($query);
                                    echo "$result";
                                  if ($query) 
                                   {
                                   echo "Here are the results:<br><br>";
                                   
                                   echo '<div id="maincontainer">';
                                 
                                   echo '</div>';
                                   while ($r = mysql_fetch_array($result,MYSQL_ASSOC)) { // Begin while 
$ts = $r["TimeStamp"]; 
$name = $r["Name"]; 
$last = $r["Last"]; 
$email = $r["email"]; 
$comment = $r["comment"]; 
echo "<tr> 
<td>$ts</td> 
<td>$name</td> 
<td>$last</td> 
<td>$email</td></tr> 
<tr> <td colspan=4 bgcolor=\"#ffffa0\">$comment</td> 
</tr>"; 
} // end while 
echo "</table>"; 
} 
else { echo "problems...."; } 
} else { 
echo "Search string is empty. <br> Go back and type a string to search"; 
} 
                          
                          
                          
                          ?>
                          
                    </div>

I get the following error

Warning : mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\wordpress\wp-content\themes\info-site\results.php on line 85

 

thanks

What is your output from this line:

 

$result = mysql_query($query);
echo "$result";

 

Also you probably want to modify the following:

if ($query) 
{
    echo "Here are the results:<br><br>";

 

to

 

if ($result) 
{
    echo "Here are the results:<br><br>";

 

Its the $result variable that you need to check. When an error occurs, $result will contain the value "false".

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.