Error help: not a valid mysql result
Posted: Mon Jul 29, 2002 7:17 am
Hi,
Back again with my joke DB.
Everything is working as it should, but i still get an error message when the user votes on a joke.
The error is:
Below you can find the source which handles the rating, in hopes that someone can find any errors in it. Line 50 is the while ($row = mysql_fetch_array($mysql_result))
PS: Sorry for bad language etc in the source, but it has been translated in a hurry, since it's original language is Norwegian.
Back again with my joke DB.
Everything is working as it should, but i still get an error message when the user votes on a joke.
The error is:
The script still works, and the rating etc is updated in my DB, and all other scripts shows both grades and results without any problems.Warning: Supplied argument is not a valid MySQL result resource in /var/www/html/demo/rating.php on line 50
Below you can find the source which handles the rating, in hopes that someone can find any errors in it. Line 50 is the while ($row = mysql_fetch_array($mysql_result))
PS: Sorry for bad language etc in the source, but it has been translated in a hurry, since it's original language is Norwegian.
Code: Select all
<?php
/* Included in funksjoenr.php is:
# Connect to the server
$connection=mysql_pconnect("localhost","root","fjokt6a");
# Check connection
if (!$connection) {
echo "Could not connect to the mySQL server!";
exit;
}
# Select the database to use
$db=mysql_select_db("vitser",$connection);
# Check to see that switch is OK
if (!$db) {
echo "Klarte ikke endring til databasen!";
exit;
}
*/
include ("funksjoner.php");
$sql="SELECT * FROM vitser WHERE ID = '$id'";
$mysql_result=mysql_query($sql,$connection);
$num_rows=mysql_num_rows($mysql_result);
if ( $num_rows == 0 )
{
echo "Sorry, no information";
}
else
{
while ($row = mysql_fetch_array($mysql_result))
{
$id=$rowї"ID"];
$FileName=$rowї"FileName"];
$Num_Votes=$rowї"Num_Votes"];
$Votes=$rowї"Votes"];
$Rating = $rowї"Rating"];
$ID=$rowї"ID"];
$vedlegg=$rowї"vedlegg"];
$new_Votes=$Num_Votes+1;
$Votes=$Votes+$Rate;
$Rating=round(($Votes/$new_Votes),2);
$sql="UPDATE vitser SET Num_Votes='$new_Votes', Votes='$Votes', Rating='$Rating' where id='$id'";
$mysql_result= mysql_query($sql, $connection) or die
("Trying to update DB - Could not execute query : $sql." . mysql_error());
}
if (!mysql_query($sql,$connection))
{
print "$software - $version";
print "<br><br>";
print "$navbar";
print "ERROR: The record could not be updated!!!<br> ";
exit;
} else
{
# Record added
print "$software - $version";
print "<br><br>";
print "$navbar<br><br>";
print "The joke now has a rating of <b>$Rating</b> after your vote.<br><br><br>";
}
}
mysql_close($connection);
?>