Main Menu |
|
|
 |
Forums |
| |
 |
Programming
Contest |
| |
 |
Documentation
|
| |
 |
Partner
Sites |
|
 |
|
| MySQL Help Post any question relating to MySQL here and hopefully someone can help |

2007-01-13, 09:53 AM
|
|
Junior Member
|
|
Join Date: Jan 2007
Posts: 12
|
|
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
$row = mysql_fetch_array($ret); ( Point of error)
$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.
|

2007-01-13, 12:54 PM
|
|
Member
|
|
Join Date: Jan 2007
Location: SPb, Russia
Posts: 30
|
|
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 "")
|

2007-01-13, 01:45 PM
|
|
Junior Member
|
|
Join Date: Jan 2007
Posts: 12
|
|
Quote:
Originally Posted by powerdesign
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"];
|

2007-01-13, 01:55 PM
|
|
Member
|
|
Join Date: Jan 2007
Location: SPb, Russia
Posts: 30
|
|
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.'<br /> 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.
|

2007-01-13, 03:28 PM
|
|
Junior Member
|
|
Join Date: Jan 2007
Posts: 12
|
|
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.
|
| Must read Review for Serious PHP Developers |
NuSphere PhpED 5.5
: The Staff of php-editors.com recently spent a few days working with NuSphere
PhpED 5.5
(a popular PHP IDE) and
NuCoder 2.0
(a PHP Encoding Utility), read up on all the details.
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 11:36 PM.
|
|