View unanswered posts | View active topics It is currently Mon Dec 17, 2018 3:56 am



Reply to topic  [ 5 posts ] 
 mysql_fetch_array(): supplied argument is not a valid "Error" 
Author Message
Junior Member

Joined: Fri Jan 05, 2007 8:22 pm
Posts: 12
Post mysql_fetch_array(): supplied argument is not a valid "Error"
I keep getting the above error, and have went over the script a hundred times. Can anyone see where I have made my mistake? I have put where the error is received in bold and underline

"Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/XXXX/public_html/update.php on line 54"

Code:
$cid=mysql_connect ("localhost", "XXXX", "XXXXX) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("XXXX", $cid);
    # processed when form is submitted back onto itself
    if ($REQUEST_METHOD=="POST") {
        # setup SQL statement
        $SQL = " UPDATE books SET";
        $SQL = $SQL . " Book = '$Book', ";
        $SQL = $SQL . " Year = '$Year', ";
        $SQL = $SQL . " Author = '$Author', ";
        $SQL = $SQL . " Genre = '$Genre' ";
        $SQL = $SQL . " Number = '$Number' ";
        $SQL = $SQL . " Series = '$Series' ";
        $SQL = $SQL . " Complete = '$Complete' ";
        $SQL = $SQL . " Recommendation = '$Recommendation' ";
        $SQL = $SQL . " Status = '$Status' ";
        $SQL = $SQL . " WHERE id = $id ";

        # execute SQL statement
        $result = mysql_db_query($db,"$SQL",$cid);
        # check for errors
        if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n");    }
        echo ("<P><B> Link Updated</B></P>\n");
    }
    else { # display edit form (not post method)
        # setup SQL statement to retrieve link
        # that we want to edit

        $SQL = " SELECT * FROM books ";
        $SQL = $SQL . " WHERE id = $id ";
        # execute SQL statement
        $ret = mysql_db_query($db,$SQL,$cid);
        # retrieve values
        [B][I][U]$row = mysql_fetch_array($ret); ( Point of error)[/U][/I][/B]
        $Book = $row["Book"];
        $Year = $row["Year"];
        $Author = $row["Author"];
        $Genre = $row["Genre"];
        $Number = $row["Number"];
        $Series = $row["Series"];
        $Complete = $row["Complete"];
        $Recommendation = $row["Recommendation"];
        $Status = $row["Status"];
?>


Of course there is a form that goes with it, that form shows up fine.
Thanks in advance.


Sat Jan 13, 2007 8:53 am
Report this post
Profile
Junior Member

Joined: Sat Jan 13, 2007 11:08 am
Posts: 31
Location: SPb, Russia
Post 
first of all, why do you use mysql_db_query instead of mysql_query ?
the official documentation says that "This function is deprecated, do not use this function. Use mysql_select_db() and mysql_query() instead." (http://php.net/manual/en/function.mysql-db-query.php)

the second question is why do u use construction $result = mysql_db_query($db,"$SQL",$cid); 14 lines above and then $ret = mysql_db_query($db,$SQL,$cid); (here $SQL is not in "")


Sat Jan 13, 2007 11:54 am
Report this post
Profile WWW
Junior Member

Joined: Fri Jan 05, 2007 8:22 pm
Posts: 12
Post 
powerdesign wrote:
first of all, why do you use mysql_db_query instead of mysql_query ?
the official documentation says that "This function is deprecated, do not use this function. Use mysql_select_db() and mysql_query() instead." (http://php.net/manual/en/function.mysql-db-query.php)

the second question is why do u use construction $result = mysql_db_query($db,"$SQL",$cid); 14 lines above and then $ret = mysql_db_query($db,$SQL,$cid); (here $SQL is not in "")


I am not sure. This is a script that i am emulating to update or correct the database and it is copied from this website.

I have changed all that to this (got rid of the $db as well)
I still get the same error
Code:
if ($REQUEST_METHOD=="POST") {
        # setup SQL statement
        $SQL = " UPDATE `books` SET ";
        $SQL = $SQL . " Book = '$Book', ";
        $SQL = $SQL . " Year = '$Year', ";
        $SQL = $SQL . " Author = '$Author', ";
        $SQL = $SQL . " Genre = '$Genre' ";
        $SQL = $SQL . " Number = '$Number' ";
        $SQL = $SQL . " Series = '$Series' ";
        $SQL = $SQL . " Complete = '$Complete' ";
        $SQL = $SQL . " Recommendation = '$Recommendation' ";
        $SQL = $SQL . " Status = '$Status' ";
        $SQL = $SQL . " WHERE `Key` = $id ";
        # execute SQL statement
        $result = mysql_query($SQL,$cid);
        # check for errors
        if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n");    }
        echo ("<P><B> Link Updated</B></P>\n");
    }
    else { # display edit form (not post method)
        # setup SQL statement to retrieve link
        # that we want to edit
        $SQL = " SELECT * FROM `books` ";
        $SQL = $SQL . " WHERE Key = $Key ";
        # execute SQL statement
        $ret = mysql_query($SQL,$cid);
        # retrieve values
        $row = mysql_fetch_array($ret);
        $Book = $row["Book"];
        $Year = $row["Year"];
        $Author = $row["Author"];
        $Genre = $row["Genre"];
        $Number = $row["Number"];
        $Series = $row["Series"];
        $Complete = $row["Complete"];
        $Recommendation = $row["Recommendation"];
        $Status = $row["Status"];


Sat Jan 13, 2007 12:45 pm
Report this post
Profile
Junior Member

Joined: Sat Jan 13, 2007 11:08 am
Posts: 31
Location: SPb, Russia
Post 
an error like "mysql_fetch_array(): supplied argument is not a valid MySQL result" gets when you have no results from query, for example.

try to debug your actions, say put this
echo 'the query is: '.$SQL.'
and error: '.mysql_error(); die;

after your
# execute SQL statement
$ret = mysql_query($SQL,$cid);

and see if there any errors with you request to DB.
also you get you query text - check it, and if you have phpmyadmin, try to paste it there and executr sql query from phpmyadmin - look if there any errors.

_________________
Link Foundation Inc. development center | Web-site design, support


Sat Jan 13, 2007 12:55 pm
Report this post
Profile WWW
Junior Member

Joined: Fri Jan 05, 2007 8:22 pm
Posts: 12
Post 
Thanks, that helped greatly in finding the syntax errors, I can at least open the page with no errors!

You were a great help, thank you. I find these things are usually right in front of you and you cant see them through the window.


Sat Jan 13, 2007 2:28 pm
Report this post
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.