When I put in the suggested code I get this back before rating:
Array
(
[go] => ratelink
[id] => 117
)
Array
(
)
Rating A1 Truck Parts:
and this:
Array
(
[go] => rate
[id] =>
)
Array
(
[idrate] =>
[Rate] => 4
)
after rating...
I believe I have truied about every iteration of the SQL query from the original posted, to the POST, to GET, etc... all with and without quotes and for id and idrate.... I also tried eliminating the single quotes around id and idrate trying that as well....
I am definitely a bit stumped....
That said.... the latest version is this:
$q = "SELECT id, name FROM links WHERE id={$_GET[id]}";
and that actually pops up the rating box instead of the original error, but once you select a rating and click submit, it spits out a new error:
Could not execute query : SELECT id, name FROM links WHERE id=.You have an error in your SQL syntax near '' at line 1
Here are the current files in case anyone is wondering after the sundry changes we have made:
Rate.php
Code: Select all
<?
require_once ('config.inc.php');
require_once ('dbconn.php');
$q = "SELECT id, name FROM links WHERE id={$_GET[id]}";
$result= mysql_query($q);
if (!$result) { die ("Could not execute query : $q." . mysql_error()); }
while ($row = mysql_fetch_array($result))
{
$id=$row["id"];
$Filename=$row["name"];
$Num_Votes=$row["Num_Votes"];
$Votes =$row["Votes"];
$Rating=$row["Rating"];
$new_Votes=$Num_Votes+1;
$Votes=$Votes+$Rate;
$Rating=round(($Votes/$new_Votes),2);
}
$q="UPDATE links SET ";
$q = $q . " Num_Votes='$new_Votes', Votes='$Votes', Rating='$Rating' ";
$q = $q . " WHERE id='$idrate' ";
$result= mysql_query($q) or die
("Could not execute query : $q." . mysql_error());
if ($result) {
echo "Thank you. The website has rating of $Rating after your vote. <a href=index.php>Go back</a>";
}
?>
RateLink.php
Code: Select all
<?
require_once ('config.inc.php');
require_once ('dbconn.php');
?>
<html>
<head></head>
<body>
<?php
$q = "SELECT id, name FROM links WHERE id={$_GET[id]}";
$result= mysql_query($q) or die
("Could not execute query : $q." . mysql_error());
if ($row=mysql_fetch_array($result))
{
$id=$row["id"];
$FileName=$row["name"];
} else {
echo "cant't find this link<br>";
}
?>
Rating <?php echo "$FileName"; ?>: <form action="<?php echo "index.php?go=rate&id=$idrate"; ?>" method="post">
<input type=hidden name=idrate value=<?=$idrate?>>
<select name="Rate">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<input type="submit" value="Rate">
</form>
</body>
</html>
Thank again for all the assistance....
JM