32 users online (1 members and 31 guests)  


  Results 1 to 5 of 5

Related

  1. Replies: 4
  2. Need help with MySQL fetch    Forum: Databases
    Replies: 2
  3. mysql fetch array error please help    Forum: PHP Forum
    Replies: 10
  4. How to fetch an image from the internet?    Forum: CGI Perl Forum
    Replies: 3
  5. fetch array problems    Forum: PHP Forum
    Replies: 4
  1. #1
    spatter's Avatar
    New User

    Status
    Offline
    Join Date
    Jun 2003
    Posts
    13

    Question php - fetch array error

    I've pulled records from database several times in the past, but I can't figure out what I'm doing wrong here. Please help.

    I get this error message:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mimsglob/public_html/database/allreps.php on line 46


    when I use this code:


    <?php

    $dbh=mysql_connect ("localhost", "mimsglob_team", "*******") or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db ("mimsglob_mimglobal", $dbh);

    $result = mysql_query( "SELECT * FROM reps" );

    while ($myrow = mysql_fetch_array($result)) {

    $lname = $myrow["lname"];
    $fname = $myrow["fname"];
    $mgnum = $myrow["mgnum"];
    $region = $myrow["region"];
    $state = $myrow["state"];
    $metro = $myrow["metro"];
    $mrdate = $myrow["mrdate"];
    $code = $myrow["code"];

    printf("<tr> \n ");
    printf(" <td><a href=\"edit.php\">Edit</td>\n ");
    printf(" <td><a href=\"delete.php\">Delete</td>\n ");
    printf(" <td>(%s)</td><td>%s:</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>\n ", $lname, $mgnum, $region, $state, $metro, $mrdate, $code );
    printf("</tr>\n ");

    }
    ?>

    Edited to remove db password

  2. #2
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    I know its a silly question, but does the table 'reps' definitely exist in that database?
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  3. #3
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    oh, and try amending to

    Code:
    $result = mysql_query( "SELECT * FROM reps", $dbh);
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  4. #4
    spatter's Avatar
    New User

    Status
    Offline
    Join Date
    Jun 2003
    Posts
    13
    yeah, i've double-checked the spellings and case of all names. The table looks fine.

    And I have tried
    $result = mysql_query( "SELECT * FROM reps", $dbh);
    $result = mysql_query( "SELECT * FROM 'reps'", $dbh);
    $result = mysql_query( "SELECT * FROM 'reps'");

    all give the same error.

  5. #5
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Then the problem must be before that.

    You have good error handling on the mysql_connect, how about adding some error handling to the select_db?

    Also, it wouldn't hurt to do the same for the select.

    the problem (one of, sorry) with mySQL & php is that most of the errors are silent, so you have to code in your own error reporting to try to see what the problem is.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?



Tags for this Thread