php error warning

Problems with the Windows version of XAMPP, questions, comments, and anything related.

php error warning

Postby turner66 » 06. June 2012 16:43

I get these errors Warning: mysql_fetch_field() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\php1\htdocs\search.php on line 44

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\php1\htdocs\search.php on line 49
when I run my code
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html lang="EN" dir="ltr" xmlns="">
    <meta http-equiv="content-type" content="text/xml; charset=utf-8" />
    <style type = "text/css">
      table, th, td {
        border: 1px solid black;

    <h1>My Contacts</h1>
  $sql = processInput();
  function processInput(){
    $srchVal = $_POST["srchVal"];
    $srchField = $_POST["srchField"];

    $conn = mysql_connect("localhost", "root", "apollo66");
    $sql = "SELECT * FROM contact WHERE $srchField LIKE '%$srchVal%'";
    return $sql;
  function printResults($sql){
    $conn = mysql_connect("localhost", "root", "apollo66");

    $result = mysql_query($sql, $conn);

    print "  <table> \n";

    print "      <tr> \n";
    while ($field = mysql_fetch_field($result)){
      print "        <th>$field->name</th> \n";
    print "      </tr> \n";

    while ($row = mysql_fetch_assoc($result)){
      print "      <tr> \n";
      foreach ($row as $name => $value){
        print "        <td>$value</td> \n";   
      print "      </tr> \n";


    print "    </table> \n";

Any Idea what the problem is and how I can fix it?
Posts: 1
Joined: 06. June 2012 16:28
Operating System: Windows XP

Re: php error warning

Postby Altrea » 06. June 2012 16:56

Hi turner66,

Wrong forum. I have moved your thread to the correct place. Next time take some minutes to orientate yourself at this board first.

Your headline is far away from being self speaking. There are hundreds of php error warnings you can get.

There is always time for an introducing welcome line if you start a new thread, especially if you want to get help at a community board. It's a matter of politeness.

back to your problem.

Thats your problem lines:
Code: Select all
while ($field = mysql_fetch_field($result)){
while ($row = mysql_fetch_assoc($result)){

Ask yourself:
- How can parameter1 ($result) can be an boolean? (var_dump() can help you to find out which boolean it is)
- where does $return come from and what does that function it comes from return in which situations? (on you can find all core php functions and their return values)

best wishes,
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
AF Moderator
Posts: 9450
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 43 guests