Simple sql error

Discussion in 'PHP' started by mikmik, Nov 7, 2005.

  1. #1
    I wonder if this is an incorrect sql query - in newer versions of MySQL? - mysql_fetch_array()

    This is the error message:
    this is the query
    Now, it runs fine on the website (i didn't make it, LOL) http://www.thebesthomes.ca/

    but I put everything onto my computer, imported the db, made sure all permissions and names are correct.

    This is the second time I've gotten this error on a script that works on the real website. That is why I am wondering if this is legacy??? I cannot see it, but I want to rule it out. I have the newest installation of phpMyAdmin and MySQL on my computer.

    Thanks for helping the brand new php nooblette! (LMAO)
     
    mikmik, Nov 7, 2005 IP
  2. frankm

    frankm Active Member

    Messages:
    915
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    83
    #2
    before the code you quoted you have probably something like:

    $sql = mysql_query("SELECT * FROM table");

    that query fails for some reason, and thus is $sql == NULL and the following mysql_fetch_array($sql) fails.

    Before this code you can put:
    if (!$sql) {
    die(mysql_error());
    }

    to get more information.

    As it does run on your website but not locally, you have probably not set permission to connect to the database right on your local machine. but that's just a guess :)
     
    frankm, Nov 7, 2005 IP
  3. mikmik

    mikmik Guest

    Messages:
    356
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks, frankm.

    I will look for other errors using 'select from table' and I think you are right, it must be permissions somewhere! At least I know it should work!
     
    mikmik, Nov 7, 2005 IP
  4. hnn

    hnn Peon

    Messages:
    91
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can also do this.
    
    $query = mysql_error("SELECT * FROM table") or die(mysql_error());
    
    PHP:
     
    hnn, Nov 7, 2005 IP
  5. sarahk

    sarahk iTamer Staff

    Messages:
    28,841
    Likes Received:
    4,543
    Best Answers:
    123
    Trophy Points:
    665
    #5
    shouldn't
    while($category=mysql_fetch_array($sql)) {
    Code (markup):
    be
    $result = mysql_query($sql) or die(mysql_error() . '<br>'.$sql);
    while($category=mysql_fetch_array([b]$result[/b])) {
    Code (markup):
     
    sarahk, Nov 8, 2005 IP