mysql_fetch_array(): supplied argument is not a valid MySQL result resource

mysql_fetch_array(): supplied argument is not a valid MySQL result resource

am 30.11.2006 00:38:45 von dan

I've been getting this error below:

mysql_fetch_array(): supplied argument is not a valid MySQL result
resource

When running this code, I can't seem to figure out what is wrong.

require_once('functions.php');

$search = $_POST['term'];
$field = $_POST['field'];

do_html_header();

//query
$conn = db_connect();
$result = $conn->query("SELECT city, restaurant FROM massachusetts
WHERE $field LIKE '%$search%'");
if (!$result)
return false;


//And we display the results
while($data = mysql_fetch_array($result))
{
echo $data['city'];
echo " ";
echo $data['restaurant'];
echo "
";
echo "
";
}

do_html_sidebar();
do_html_footer();

?>

my db_connect(); function is below (with the login information
changed):

function db_connect()
{
$result = new mysqli('localhost', 'user', 'password', 'database');
if (!$result)
throw new Exception('Could not connect to database server');
else
return $result;
}

And this is my search form where it gets the post variables:









Search here:




Can anybody help? Thanks

Re: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

am 30.11.2006 01:37:27 von zac.carey

Dan wrote:
> I've been getting this error below:
>
> mysql_fetch_array(): supplied argument is not a valid MySQL result
> resource
>
> When running this code, I can't seem to figure out what is wrong.
>
> > require_once('functions.php');
>
> $search = $_POST['term'];
> $field = $_POST['field'];
>
> do_html_header();
>
> //query
> $conn = db_connect();
> $result = $conn->query("SELECT city, restaurant FROM massachusetts
> WHERE $field LIKE '%$search%'");
> if (!$result)
> return false;
>
>
> //And we display the results
> while($data = mysql_fetch_array($result))
> {
> echo $data['city'];
> echo " ";
> echo $data['restaurant'];
> echo "
";
> echo "
";
> }
>
> do_html_sidebar();
> do_html_footer();
>
> ?>
>
> my db_connect(); function is below (with the login information
> changed):
>
> function db_connect()
> {
> $result = new mysqli('localhost', 'user', 'password', 'database');
> if (!$result)
> throw new Exception('Could not connect to database server');
> else
> return $result;
> }
>
> And this is my search form where it gets the post variables:
>
>


>
>
>
>
>
>
>
>
Search here:

>

>
>
> Can anybody help? Thanks

is 'query' a valid function? perhaps that should be 'mysql_query'?

Re: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

am 04.12.2006 00:36:35 von Peter

> while($data = mysql_fetch_array($result))

I have not used the mysqli class but try using $result->fetch_array()
instead of the function

You are using a class as the resource id instead of an actual resource id.

Re: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

am 04.12.2006 00:38:10 von Peter

> is 'query' a valid function? perhaps that should be 'mysql_query'?

query is a valid method in the mysqli class:-

http://www.php.net/manual/en/function.mysqli-query.php

Re: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

am 04.12.2006 00:49:44 von Rincewind

"Dan" wrote in message
news:1164843525.434746.8190@80g2000cwy.googlegroups.com...
> I've been getting this error below:
>
> mysql_fetch_array(): supplied argument is not a valid MySQL result
> resource
>
> When running this code, I can't seem to figure out what is wrong.
>
> > require_once('functions.php');
>
> $search = $_POST['term'];
> $field = $_POST['field'];
>
> do_html_header();
>
> //query
> $conn = db_connect();
> $result = $conn->query("SELECT city, restaurant FROM massachusetts
> WHERE $field LIKE '%$search%'");
> if (!$result)
> return false;
>
>
> //And we display the results
> while($data = mysql_fetch_array($result))
> {
> echo $data['city'];
> echo " ";
> echo $data['restaurant'];
> echo "
";
> echo "
";
> }
>
> do_html_sidebar();
> do_html_footer();
>
> ?>
>
> my db_connect(); function is below (with the login information
> changed):
>
> function db_connect()
> {
> $result = new mysqli('localhost', 'user', 'password', 'database');
> if (!$result)
> throw new Exception('Could not connect to database server');
> else
> return $result;
> }
>
> And this is my search form where it gets the post variables:
>
>


>
>
>
>
>
>
>
>
Search here:

>

>
>
> Can anybody help? Thanks
>

It's because you're using a mysql function (mysql_fetch_array) on a mysqli
result set.

Re: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

am 08.12.2006 20:27:15 von Da Dimmi de wit

try @mysql_fetch_array