All pastes #97550 Raw Edit

Anonymous

public text v1 · immutable
#97550 ·published 2006-07-23 21:01 UTC
rendered paste body
<?php
if($_POST[Submit])
	{
$tutorialid = $_GET[id];
$rating = $_POST[rating];
$username = $logged[username];

$checkrate = mysql_query("SELECT username && tid FROM ratings WHERE username='$username' && tid='$tutorialid'");
$checkrate= mysql_num_rows($checkrate); 
if ($checkrate>0) { 
boxtop("Error");
echo "You Have Already Rated This Tutorial <br> ";
echo ("You Will Be Redirected..");
echo ("<meta http-equiv=\"refresh\" content=\"3;URL=http://techtuts.com/?view=tutorials&act=tutorial&id=$tutorialid\">");
endbox();
}else{
$insert = mysql_query("INSERT INTO ratings (`tid`, `username`, `rating`) VALUES ( '$tutorialid', '$username', '$rating')");
$query = mysql_query("SELECT avg(rating) AS columnaverage FROM ratings");
$row = mysql_fetch_array($query);
$totalresults = $row["columnaverage"];
$round = round($round_totalresults, 1); //rounds the average into E.X 8.1 instead of 8.1837
boxtop("Thank You");
bar("Your Rating Has Been Submitted!");
echo "The New Average Rating For This Tutorial is '.$round' <br>";
echo "You Will Be Redirected..";
endbox();
echo ("<meta http-equiv=\"refresh\" content=\"3;URL=http://techtuts.com/?view=tutorials&act=tutorial&id=$tutorialid\">");
}
}
else
{

$rated = mysql_query("SELECT * FROM ratings WHERE username = '$logged[username]', tid = '.$_GET[id]'");
if ($rated == 0)
{
boxtop("Rate This Tutorial");
echo("<form method=\"post\" action=\"\">
  <select name=\"rating\">
    <option value=\"5\">5 (Excellent)</option>
    <option value=\"4\">4</option>
    <option value=\"3\">3</option>
    <option value=\"2\">2</option>
    <option value=\"1\">1 (Poor)</option>
  </select>
  <label>
  <input type=\"submit\" name=\"Submit\" value=\"Rate\">
  </label>
</form>");
endbox();
}
}
?>