Page 1 of 1

Strange mysql_fetch_array() Problem

Posted: Mon Feb 25, 2008 5:43 pm
by Dale
I've just been messing around with some code and decided to start making a kind of template system that reads from the database. I am using this little bit of code:

Code: Select all

<?php
    mysql_connect("localhost","root","");
    mysql_select_db("data");
    $getTmp = mysql_query("SELECT template FROM ".$dbprefix."templates WHERE title = 'header' LIMIT 1");
    $getTemp = mysql_fetch_array($getTmp);
    $template = $getTemp['template'];
    return $template;
?>
However it is constantly returning this error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\index.php on line 5
I'm probably being blind or something, but I cannot seem to find what is wrong, anyone care to point it out?

Re: Strange mysql_fetch_array() Problem

Posted: Mon Feb 25, 2008 6:01 pm
by Benjamin
The query is failing.

Re: Strange mysql_fetch_array() Problem

Posted: Mon Feb 25, 2008 6:19 pm
by Christopher
Always check for errors:

Code: Select all

<?php
    mysql_connect("localhost","root","");
    mysql_select_db("data");
    $getTmp = mysql_query("SELECT template FROM ".$dbprefix."templates WHERE title = 'header' LIMIT 1");
    if (! mysql_errno()) {
        $getTemp = mysql_fetch_array($getTmp);
        $template = $getTemp['template'];
    } else {
        $template = mysql_error();
    }
    return $template;
?>