eekhoorn Posted June 6, 2007 Share Posted June 6, 2007 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 Quote Link to comment Share on other sites More sharing options...
chocopi Posted June 6, 2007 Share Posted June 6, 2007 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 Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted June 6, 2007 Share Posted June 6, 2007 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. Quote Link to comment Share on other sites More sharing options...
eekhoorn Posted June 6, 2007 Author Share Posted June 6, 2007 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 Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted June 6, 2007 Share Posted June 6, 2007 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. Quote Link to comment Share on other sites More sharing options...
eekhoorn Posted June 6, 2007 Author Share Posted June 6, 2007 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 Quote Link to comment Share on other sites More sharing options...
eekhoorn Posted June 6, 2007 Author Share Posted June 6, 2007 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! Quote Link to comment Share on other sites More sharing options...
eekhoorn Posted June 6, 2007 Author Share Posted June 6, 2007 Thanks for all your help by the way Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.