www.webdeveloper.com
Results 1 to 5 of 5

Thread: I'm getting errors...

  1. #1
    Join Date
    Aug 2006
    Posts
    57

    I'm getting errors...

    hi, i'm getting errors when i run php the errors said

    "Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in "

    these error were talking about the while statements ...where it said "while($row = mysql_fetch_array($data))"

    PHP Code:
    <form action="" method="get">
        <?php
            
    include("db.php");
            
    $dbc = new mysqli($mysql_hostname$mysql_user$mysql_password$mysql_database);
            
    $query  "SELECT checks,id FROM dragdrop ORDER BY id ASC";
            
    $data mysqli_query($dbc$query);
            while(
    $row mysql_fetch_array($data))
            {
                
    $idstripslashes($row['id']);
                
    $checkstripslashes($row['checks']);
                echo 
    "<input id='check$id' type='checkbox' onchange='fun($id)' ";
                
                if(
    $check==1)
                    echo 
    "checked='true'>$id<br>";
                else
                    echo 
    ">$id<br>";
                
            }

        
    ?>

        </form>
    What this mean and how can i solve that!

    please help thanks.

    AM

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,617
    It means your query failed to process, so mysqli_query() returned Boolean false instead of a mysqli_result object.

    I always test the value of query statements and add some error-logging code if it returns false. A quick way:
    PHP Code:
    if(($data mysqli_query($dbc$query)) == false) {
        throw new 
    Exception("Query error: ".mysqli_error($dbc).PHP_EOL.$sql);

    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Aug 2006
    Posts
    57
    Quote Originally Posted by NogDog View Post
    It means your query failed to process, so mysqli_query() returned Boolean false instead of a mysqli_result object.

    I always test the value of query statements and add some error-logging code if it returns false. A quick way:
    PHP Code:
    if(($data mysqli_query($dbc$query)) == false) {
        throw new 
    Exception("Query error: ".mysqli_error($dbc).PHP_EOL.$sql);

    thanks so much but where do i need to put this code at for me to test it!

    AM

  4. #4
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    878
    This IS the code that tests your query and gives you error messages if the query fails. If it succeeds then your script will continue on to the fetch will now be valid.

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,617
    It replaces (and includes) this line in your original code:
    PHP Code:
    $data mysqli_query($dbc$query
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles