Jump to content
Larry Ullman's Book Forums

Error Mysequl_Fetch_Arrary () Expects Parameter 2 To Be Long


Recommended Posts

This error keeps occuring:

 

Warning: mysql_fetch_array() expects parameter 2 to be long, resource given in /home/content/83/9391183/html/delete_quote.php on line 25.

 

 

 

A portion of the code (from chapter 13):

 

 

if ( isset($_GET['id']) && is_numeric($_GET['id']) && ($_GET['id'] > 0 ) ) {

 

$query = "SELECT quote, source, favorite FROM quotes WHERE quote_id={$_GET['id']} LIMIT 1";

 

if ( $r = mysql_query($query, $dbc) ) {

 

$row = mysql_fetch_array($r, $dbc); <<<<<<<<<<< LINE 25

 

 

 

I don't know what else to add that might be useful. No problems with adding or deleting from the database's table, nor with listing all of the entries from a table. This error seems to occur only when trying to 'SELECT' a specific row in the table and then print it to the web browser. I've tried different web browsers. No luck. I'm using an exact copy of the code that is in the book (EDIT: this is not true. i added a parameter in line 25 w/o realizing it, even after double checking that my code matched the books. the book's code is 100% error free. sorry about that.) That leads me to think it might be a configuration issue, but I don't know. I'm using a webserver and mysql database thru godaddy.com.

 

I had this same exact error (mysql_fetch_array() expects parameter 2 to be long) when working with the examples in chapter 12.

 

Please help. Any help is greatly appreciated! Thanks in advance.

Link to comment
Share on other sites

The second parameter for mysql_fetch_array which is optional lets you specify the type of array that is returned, either numeric or associative. Try

$row = mysql_fetch_array($r);

 

Refer to the php manual for more information on the second parameter.

  • Upvote 2
Link to comment
Share on other sites

In my original post, I said I was using an exact copy of the code in the book, but I just realized this was not true! The code in the book is 100% correct, as expected. My apologies to the author.

Link to comment
Share on other sites

 Share

×
×
  • Create New...