I am using the star rating system from another site (it is linked soewhere in this site)
The code
<link href="stylesheet.css" rel="stylesheet" type="text/css">
<?php
function ratemenu(){
$tut_id= $_GET['tut_id'];
echo "<form name=\"rating\" action=\"star_rating.php\">
Rate this Products:
<input type=\"hidden\" name=\"tut_id\" value=\"$tut_id\">
<select name=\"rating\" class=\"input\">
<option value=\"5.0\" selected>5 - Excellent!</option>
<option value=\"4.0\">4</option>
<option value=\"3.0\">3 - Fair</option>
<option value=\"2.0\">2</option>
<option value=\"1.0\">1 - Poor</option>
<option value=\"0.0\">0 - Awful!</option>
<input type=\"submit\" value=\"Go!\" class=\"input\">
</select>
</form>";
}
include 'config.php';
mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die (mysql_error());
$tut_rating=mysql_query("SELECT tut_rating, tut_num_votes FROM star WHERE tut_id='$tut_id'");
function tut_stars($tut_rating){
if((($tut_rating >= 0)or($tut_rating == 0)) && ($tut_rating <= 0.50)){
echo "<img src=\"/images/stars/0o5.gif\" width=\"70\" height=\"18\">";
}
if((($tut_rating >= 0.50)or($tut_rating == 0.50)) && ($tut_rating <= .99)){
echo "<img src=\"/images/stars/05o5.gif\" width=\"70\" height=\"18\">";
}
if((($tut_rating >= 1.00)or($tut_rating == 1.50)) && ($tut_rating <= 1.49)){
echo "<img src=\"/images/stars/1o5.gif\" width=\"70\" height=\"18\">";
}
if((($tut_rating >= 1.50)or($tut_rating == 1.50)) && ($tut_rating <= 1.99)){
echo "<img src=\"/images/stars/15o5.gif\" width=\"70\" height=\"18\">";
}
if((($tut_rating >= 2.00)or($tut_rating == 2.00)) && ($tut_rating <= 2.49)){
echo "<img src=\"/images/stars/2o5.gif\" width=\"70\" height=\"18\">";
}
if((($tut_rating >= 2.50)or($tut_rating == 2.50)) && ($tut_rating <= 2.99)){
echo "<img src=\"/images/stars/25o5.gif\" width=\"70\" height=\"18\">";
}
if((($tut_rating >= 3.00)or($tut_rating == 3.00)) && ($tut_rating <= 3.49)){
echo "<img src=\"/images/stars/3o5.gif\" width=\"70\" height=\"18\">";
}
if((($tut_rating >= 3.50)or($tut_rating == 3.50)) && ($tut_rating <= 3.99)){
echo "<img src=\"/images/stars/35o5.gif\" width=\"70\" height=\"18\">";
}
if((($tut_rating >= 4.00)or($tut_rating == 4.00)) && ($tut_rating <= 4.49)){
echo "<img src=\"/images/stars/4o5.gif\" width=\"70\" height=\"18\">";
}
if((($tut_rating >= 4.50)or($tut_rating == 4.50)) && ($tut_rating <= 4.99)){
echo "<img src=\"/images/stars/45o5.gif\" width=\"70\" height=\"18\">";
}
if($tut_rating == 5.0){
echo "<img src=\"/images/stars/5o5.gif\" width=\"70\" height=\"18\">";
}
}
function section2(){
echo "Great! You have made it to section 2.<a href=\"?cmd=index\">Go back to the index</a>";
}
switch($_REQUEST['cmd']){ //updated to work with register_globals "off";
default:
index();
break;
case "section2":
section2();
break;
}
function index(){
echo "Weclcome to my php site!<a href=\"?cmd=section2\">Click Here to go to the next section!</a>";
echo ratemenu($tut_id);
echo tut_stars($tut_rating);
}
?>
Star_rating.php is
<?php
$tut_id=$_GET['tut_id'];
echo "$tut_id";
function tut_stars($tut_rating){
include 'config.php';
mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die (mysql_error());
$tut_id=$_GET['tut_id'];
echo "$tut_id";
$sql = "SELECT * FROM star WHERE tut_id='$tut_id'";
mysql_query($sql) or die (mysql_error());
if((($tut_rating >= 0)or($tut_rating == 0)) && ($tut_rating <= 0.50)){
echo "<img src=\"/images/stars/0o5.gif\" width=\"70\" height=\"18\">";
}
if((($tut_rating >= 0.50)or($tut_rating == 0.50)) && ($tut_rating <= .99)){
echo "<img src=\"/images/stars/05o5.gif\" width=\"70\" height=\"18\">";
}
if((($tut_rating >= 1.00)or($tut_rating == 1.50)) && ($tut_rating <= 1.49)){
echo "<img src=\"/images/stars/1o5.gif\" width=\"70\" height=\"18\">";
}
if((($tut_rating >= 1.50)or($tut_rating == 1.50)) && ($tut_rating <= 1.99)){
echo "<img src=\"/images/stars/15o5.gif\" width=\"70\" height=\"18\">";
}
if((($tut_rating >= 2.00)or($tut_rating == 2.00)) && ($tut_rating <= 2.49)){
echo "<img src=\"/images/stars/2o5.gif\" width=\"70\" height=\"18\">";
}
if((($tut_rating >= 2.50)or($tut_rating == 2.50)) && ($tut_rating <= 2.99)){
echo "<img src=\"/images/stars/25o5.gif\" width=\"70\" height=\"18\">";
}
if((($tut_rating >= 3.00)or($tut_rating == 3.00)) && ($tut_rating <= 3.49)){
echo "<img src=\"/images/stars/3o5.gif\" width=\"70\" height=\"18\">";
}
if((($tut_rating >= 3.50)or($tut_rating == 3.50)) && ($tut_rating <= 3.99)){
echo "<img src=\"/images/stars/35o5.gif\" width=\"70\" height=\"18\">";
}
if((($tut_rating >= 4.00)or($tut_rating == 4.00)) && ($tut_rating <= 4.49)){
echo "<img src=\"/images/stars/4o5.gif\" width=\"70\" height=\"18\">";
}
if((($tut_rating >= 4.50)or($tut_rating == 4.50)) && ($tut_rating <= 4.99)){
echo "<img src=\"/images/stars/45o5.gif\" width=\"70\" height=\"18\">";
}
if($tut_rating == 5.0){
echo "<img src=\"/images/stars/5o5.gif\" width=\"70\" height=\"18\">";
}
}
echo tut_stars($tut_rating);
if (session_is_registered("tut$tut_id")){
echo "<center>Sorry! You have already voted!";
} else {
include 'config.php';
mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die (mysql_error());
$get_count = mysql_query("SELECT tut_rating, tut_num_votes FROM star WHERE tut_id=$tut_id");
while(list($tut_rating, $tut_num_votes)=mysql_fetch_array($get_count)){
$new_count = ($tut_num_votes + 1);
$tut_rating2 = ($tut_rating * $tut_num_votes);
$new_rating = (($rating + $tut_rating2) / ($new_count));
$new_rating2 = number_format($new_rating, 2, '.', '');
$update_rating = mysql_query("UPDATE star SET tut_rating='$new_rating2',tut_num_votes='$new_count' WHERE tut_id=$tut_id");
$sessionvar = "tut$tut_id";
session_register($sessionvar);
echo "<div align=\"center\"><b>
<p>Thanks for your vote!</p>
<p>The new rating for this tutorial is:
$new_rating2 out of 5</p>";
}
}
echo "<p align=\"center\"><a href=\"javascript:history.back();\"><<
Back</a> | <a href=\"/index.php\">Main Page</a> | <a href=\"/tutorials.php\">Tutorial
Index>></a></b>
</p>";
?>
When i go to select the star rating, the tut_id is not passed over therefor nothing happens.
Also the rating calculator does not work
Can anyone see y?
David