Page 2 of 2

Posted: Thu Apr 08, 2004 7:11 pm
by markl999
In your second post you say
$q= "SELECT * FROM links WHERE id={$_GET['idrate']};
and i notice you still have a parse error on that page, it should be:

$q= "SELECT * FROM links WHERE id={$_GET['idrate']}";

I'm not sure if that is still your problem, if not, then can you repost the code you have now, specifically line 14 of ratelink.php (which is currently giving a parse error)

Posted: Fri Apr 09, 2004 3:19 pm
by twigletmac
tim wrote:twig, mark already suggested such a method ($_GET) - as well as he said he tried it in a variety of different ways with no luck.
With id as the var not idrate? I don't see idrate in the URL but I do see id, that's why I suggested using $_GET['id']. Just read throught the thread again and don't see where $_GET['id'] was tried?

Johnnymo - at the top of the script do:

Code: Select all

echo '<pre>';
print_r($_GET);
print_r($_POST);
echo '</pre>';
and post the results here - that way we can see if anything is getting passed and what the variables are called.

Mac

Mac

Posted: Fri Apr 09, 2004 7:23 pm
by Johnnymo
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. &nbsp; <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

Posted: Sat Apr 10, 2004 10:29 am
by twigletmac
Try replacing, in rate.php and ratelink.php, this line in the while loop:

Code: Select all

$id=$row["id"];
with

Code: Select all

$idrate = $row['id'];
as $idrate is used a few times and I _think_ it should be just be the id value from the db so the above should work.

Mac