Hello. I have a rating system for a joke site. I works very simply: gets the id of the jokes (if something is wrong, it will say no such joke), gets the rating you give it and averages it out with the rating in the database. The problem is, whenever the id of the joke is over roughly 35 (maybe 36-37), it gives me the 'no such joke' error. Can someone help me? Here's the code.
<?php
//this displays the joke and lets you rate it at the bottom
$db = mysql_connect("localhost","","");
mysql_select_db("dbthawowi_2",$db);;
$callsign = $HTTP_POST_VARS['id'];
$callsign = $_GET['id'];
$query = "SELECT * FROM userjokes WHERE id='$id'";
$resultat = mysql_query($query) or die(mysql_error());
$row= mysql_fetch_object($resultat);
echo "Joke number ";
print"$row->id<br><br>";
print"$row->joke<br><br>";
echo "Joke submitted by: ";
print"$row->name ";
echo "on ";
$date_from_db = "$row->date";
$formatted_date = date("m/j/y",time($date_from_db));
echo $formatted_date;
?>
<HTML>
<body>
<form method="POST" action="pratingsystem.php">
<?php
echo "<input type=\"hidden\" name=\"jokeId\" value="$id">";
?>
<input type="radio" value="5" checked name="rating">Excellent
<input type="radio" name="rating" value="4">Good
<input type="radio" name="rating" value="3">OK
<input type="radio" name="rating" value="2">Not-so-good
<input type="radio" name="rating" value="1">Sucks</p>
<p><input type="submit" value="Submit" name="B1"></p>
</form>
</body>
</HTML>
<?php
//now let's proccess the rating and insert into the database
if (empty($rating) || !is_numeric($rating))
echo "Go back and select a rating";
else
{
$db=mysql_connect("localhost", "", "") or die(mysql_error());
mysql_select_db("dbthawowi_2", $db) or die(mysql_error());
$query = "SELECT number, total FROM evaluation WHERE id='$jokeId'";
$result = mysql_query($query, $db) or die(mysql_error());
$row = mysql_fetch_row($result) or die('no such joke');
$row[0] += 1;
$row[1] += $rating;
$secondquery = 'UPDATE userjokes SET total='.$row[1].',number='.$row[0].' WHERE id='.$jokeId;
$secondresult = mysql_query($secondquery, $db) or die(mysql_error());
$average=$row[1]/$row[0];
$thirdquery = 'UPDATE evaluation SET average='.$average.' WHERE id='.$jokeId;
$thirdresult = mysql_query($thirdquery, $db) or die(mysql_error());
echo "Thank you for rating this joke. Thanks to you, the overall rating for this joke is now $average";
}
?>
Thanks in advance for your help.