PHP Notice: Undefined index: & PHP Notice: Undefined variable:
My server as just been updated and now I'm getting the following errors on my rating script.
[Thu Sep 27 12:28:48 2012] [error] [client ***.***.**.***] PHP Notice: Undefined index: rating in /var/www/vhosts/****/public_html/rateanything.php on line 7
[Thu Sep 27 12:28:48 2012] [error] [client ***.***.**.***] PHP Notice: Undefined variable: stars in /var/www/vhosts/****/public_html/rateanything.php on line 27
[Thu Sep 27 12:28:48 2012] [error] [client ***.***.**.***] PHP Notice: Undefined variable: report in /var/www/vhosts/****/public_html/rateanything.php on line 36
The file coding is as follows, bold text being the lines:
PHP Code:
<?php
require_once('config2.php');
mysql_connect($db_server, $db_username, $db_password) or die(mysql_error());
mysql_select_db($db_database) or die(mysql_error());
$div_id = $_GET['id'];
[B]$rating = $_GET['rating'];[/B]
if($rating){
//Check that this person hasn't already left a rating
$result = mysql_query("SELECT id FROM ratings WHERE div_id = '" . $div_id . "' AND ip = '" . $_SERVER['REMOTE_ADDR'] . "'") or die(mysql_error());
$row = mysql_fetch_array( $result );
if(!$row['id']){
$result = mysql_query("INSERT INTO ratings (rating,div_id,ip) VALUES('" . $rating . "','" . $div_id . "','" . $_SERVER['REMOTE_ADDR'] . "')") or die(mysql_error()); if($result){ $report = "<span style=\"color: green;\"> You rated this: $rating</span>"; }
} else {
$report = "<span style=\"color: red;\"> You have already rated this.</span>";
}
}
?>
<?php
$result = mysql_query("SELECT avg(rating), COUNT(*) FROM ratings WHERE div_id = '" . $div_id . "'") or die(mysql_error());
$row = mysql_fetch_array( $result );
$x=1;
while($x<=5){
[B] $stars .= "<li><a onClick=\"javascript:addRating('$div_id','$x');\" class=\"star$x\">$x</a></li>";[/B]
$x++;
}
?>
<ul class='star-rating'>
<li class="current-rating" id="current-rating" style="width: <?php echo round($row[0],1) * 20; ?>%;"></li>
<? echo $stars; ?>
</ul>
[B]<div><small><?php echo "<span style=\"color: grey;\">Rating: " . round($row[0],1) . "/5 (" . $row[1] . " Ratings)</span> " . $report; ?></small></div>[/B]