Jump to content

[SOLVED] Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result


eekhoorn

Recommended Posts

Strange one this, I have checked the forum and tried everything I can that is related and it still won't work.

 

I keep getting the following error on all my code:

 

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

 

I have just moved service provider and the code worked perfectly on my old site but no longer works with my new provider the code is as below.

 

Header code:

<?php
include("../counter/counter.php");
require("connection.php");
$rs = mysql_select_db("leonrcou_leonaurbooks", $conn);
?>

 

the connection works fine as I have tested this seperately.

 

The main code is as follows and is a simple query:

<?php
$sql="SELECT `book_title`
	 FROM `book_database`
	 WHERE `book_id` = `$bookid`";

$rs=mysql_query($sql,$conn);

while($row = mysql_fetch_array($rs) )
{
echo("".$row["book_title"]."");
}
?>

 

I have checked the database and everything is the same as previously

 

Its baffling me trying to figure out what is wrong as the code was working yesterday on a separate server, any help would be fantastic thanks.

 

Gav

It might be because you havent defined what type of value you want returned

 

So try replacing

 

while($row = mysql_fetch_array($rs) )

 

For

 

while($row = mysql_fetch_array($rs, MYSQL_ASSOC))

 

I think that might work  ???

 

~ Chocopi

try this:

 

<?php
$sql="SELECT `book_title`
	 FROM `book_database`
	 WHERE `book_id` = `$bookid`";

$rs=mysql_query($sql);

while($row = mysql_fetch_array($rs) )
{
echo("".$row["book_title"]."");
}
?>

 

If this does not solve the prob than show ur db connectivity code.

Both generate the same error, my connection code is:

 

<?php

 

$user = "username";

 

$conn = mysql_connect("localhost", "$user", "password");

 

?>

 

it connects fine as I placed a message in before to tell me if ti was connected ok.

 

I'm starting to think that it may be my hosting provider, as the .com is still on the old server and works fine but the .co.uk is on the new server and is generating errors.

 

Gav

try this:

 

<?php
$sql="SELECT `book_title`
	 FROM `book_database`
	 WHERE `book_id` = `$bookid`";

$rs=mysql_query($sql);

while($row = mysql_fetch_object($rs) )
{
echo("".$row["book_title"]."");
}
?>

 

May be it will work for u.

Just generates: Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource

 

Thanks for the help, I have sent a mail to the hosting provider now to see if they can shed any light on the matter!

 

http://www.leonaur.co.uk/collections/collections.php?seriesid=1

http://www.leonaur.co.uk/books/booknumber.php?bookid=94

 

There are a couple of links out interest as to the live version of the problem.

 

Gav

Figured it out, I have put:

 

$bookid = $_GET['id'];

 

in the header so it gets the information after "book.php?bookid=1" otherwise the sql query was searching for nothing and thus returning the correct response!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.