[RESOLVED] Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in ....
Results 1 to 6 of 6

Thread: [RESOLVED] Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in ....

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    7

    resolved [RESOLVED] Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in ....

    Hello everyone! I'm new in this forum.

    I'm having a problem with my coding : when I execute the code below >>

    PHP Code:
    // Retrieve the user's information
    $query "SELECT nama, no_kp, telefon, email, masalah FROM damage_tb WHERE id=$id";
    $result = @mysql_query ($query); // Run the query.

    if(mysql_num_rows($result) == 1) { // Valid user ID, show the form.

        // Get the user's information.
        
    $row mysql_fetch_array ($resultMYSQL_NUM);
        
        
    // Create the form.
        
    echo '<h2>Kemaskini Laporan</h2>
    <form action="kemaskini.php" method="post">
    <p>Nama : <input type="text" name="nama" size="25" maxlength="30" value="' 
    $row[0]. '" /></p>
    <p>No KP : <input type="text" name="no_kp" size="25" maxlength="25" value="' 
    $row[1]. '" /></p>
    <p>Telefon : <input type="text" name="telefon" size="15" maxlength="15" value="' 
    .$row[2]. '" /></p>
    <p>Email : <input type="text" name="email" size="25" maxlength="25" value="' 
    .$row[3]. '" /></p>
    <p>Masalah : <input type="text" name="masalah" size="30" maxlength="30" value="' 
    .$row[4]. '" /></p>
    <p><input type="submit" name="Submit" value="Submit" /></p>
    <input type="hidden" name="submitted" value="TRUE" />
    <input type="hidden" name="id" value="' 
    $id '" />
    </form>'
    ;

    } else { 
    // Not a valid user ID.
    echo '<h1 id="mainhead">Page Error</h1>
    <p class="error">Laman ini telah diakses secara salah!</p><p><br /><br /></p>'
    ;

    After that this error come out :
    Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\damage\kemaskini.php on line 112

    please advice me...
    Last edited by bradgrafelman; 05-19-2010 at 01:50 PM. Reason: PHP bbcode tags added

  2. #2
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,883
    It means that MySQL failed to make sense of your query and you suppressed the error message that would have told you it failed (don't use '@' unless you know why you shouldn't). See mysql_query to see why it would return a boolean instead of a resource, and use mysql_error to see what MySQL has a problem with in your query.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  3. #3
    To code, or not to code? jkurrle's Avatar
    Join Date
    Jul 2004
    Location
    Gainesville, VA
    Posts
    520
    Many times, when you get this error, you are attempting to use or retrieve data that isn't in the table. Because of this, you are getting "false" as a result, instead of your expected data...
    99 little bugs in the code, 99 bugs in the code,
    fix one bug, compile it again...
    101 little bugs in the code....

  4. #4
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,428
    Quote Originally Posted by jkurrle View Post
    Many times, when you get this error, you are attempting to use or retrieve data that isn't in the table. Because of this, you are getting "false" as a result, instead of your expected data...
    Sorry to disagree, but that statement is definitely false.

    The only time you'll get boolean FALSE instead of a resource is if you have an error in your query. Executing a query that returns no rows isn't an error.

  5. #5
    To code, or not to code? jkurrle's Avatar
    Join Date
    Jul 2004
    Location
    Gainesville, VA
    Posts
    520
    Mea Culpa!

    What I meant was not data, but column names. My bad...
    99 little bugs in the code, 99 bugs in the code,
    fix one bug, compile it again...
    101 little bugs in the code....

  6. #6
    Junior Member
    Join Date
    May 2010
    Posts
    7

    Talking Ok, thanks all bro. I got it.

    I got it. I forgot to write escape_data function. Thanks to all.

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
  •