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 Quote Link to comment 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". Quote Link to comment Share on other sites More sharing options...
jake2891 Posted January 5, 2011 Share Posted January 5, 2011 where is your $search variable been set? Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.