Re: Supplied argument is not a valid MySQL result resource
| From: | Philip Olson | Date: | Thu, 20 Jun 2002 15:39:41 +0000 |
| Subject: | Re: Supplied argument is not a valid MySQL result resource | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-103150@lists.php.net to get a copy of this message | ||
Just a fyi, consider using mysql_error() to solve these
type of problems. For example:
On Thu, 20 Jun 2002 webmaster@tececo.com wrote:
> Here is my code:
>
> <?
Using 'or die' like this is okay, while debugging
consider putting mysql_error() in your die().
> $link = mysql_pconnect("localhost", "root", "") or
> die("Could not connect");
> mysql_select_db("tececo") or die("Could not select database");
> $fn = explode("/", $_SERVER['PHP_SELF']);
> $num_of_s = count($fn) - 1;
> $fn = "$fn[$num_of_s]";
// Make it '$fn' not $fn in your query
// (use quotes if $fn isn't a number)
> $query = "SELECT * FROM meta_data WHERE page_name = $fn";
> $result = mysql_query($query);
// mysql_query returns false on failure
if (!$result) {
echo "DB Error ($query) : " . mysql_error();
exit;
}
> $num_results = mysql_num_rows($result);
// maybe some rows should exist before we move on
if ($num_results > 0) {
> $row = mysql_fetch_array($result);
// instead of the below, you could use extract:
// http://www.php.net/extract
extract($row);
> $id = $row['id'];
> $title = $row['title'];
> $description = $row['description'];
> $keywords = $row['keywords'];
> ?>
>
> I get this error:
mysql_error() will give you a more useful meaning.
>
> Warning: Supplied argument is not a valid MySQL result resource in
> C:\TecEco(Converting To PHP)\includes\meta.array_create.php on line 9
>
> Warning: Supplied argument is not a valid MySQL result resource in
> C:\TecEco(Converting To PHP)\includes\meta.array_create.php on line 10
>
> Why?
>
> Thanks
>
> JJ Harrison
> webmaster@tececo.com
> www.tececo.com
>