diasansley Posted January 5, 2011 Share Posted January 5, 2011 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 Link to comment https://forums.phpfreaks.com/topic/223451-mysql_fetch_array-expect-parameter-1-to-be-resource/ Share on other sites More sharing options...
nderevj Posted January 5, 2011 Share Posted January 5, 2011 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". Link to comment https://forums.phpfreaks.com/topic/223451-mysql_fetch_array-expect-parameter-1-to-be-resource/#findComment-1155091 Share on other sites More sharing options...
jake2891 Posted January 5, 2011 Share Posted January 5, 2011 where is your $search variable been set? Link to comment https://forums.phpfreaks.com/topic/223451-mysql_fetch_array-expect-parameter-1-to-be-resource/#findComment-1155096 Share on other sites More sharing options...
diasansley Posted January 5, 2011 Author Share Posted January 5, 2011 i dnt kwn how but it works now!!!! thanks anyways Link to comment https://forums.phpfreaks.com/topic/223451-mysql_fetch_array-expect-parameter-1-to-be-resource/#findComment-1155177 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.