-1

这里的 JavaScript 和 CSS 运行流畅。但是每当我尝试运行 PHP 文件时,它都会显示一个错误,指出未定义的索引,如下所示:

Notice: Undefined index: do in C:\wamp\www\PROJECT\jquery_tutorial_starrating\update.php on line 8
Call Stack
#   Time    Memory  Function    Location
1   0.0016  375888  {main}( )   ..\update.php:0

Notice: Undefined index: do in C:\wamp\www\PROJECT\jquery_tutorial_starrating\update.php on line 14
Call Stack
#   Time    Memory  Function    Location
1   0.0016  375888  {main}( )   ..\update.php:0

我的html代码是:

    <html>
     <head> 

     <script src="rating/jquery.min.js" type="text/javascript"></script> 
     <script src="rating/starrating.js" type="text/javascript"></script> 
     <link href="rating/starrating.css" rel="stylesheet" type="text/css" media="screen" /> 
     </head> 
     <body> 
      <h2>Star Rater</h2> 
     <ul class='star-rating'> 
     <li class="current-rating" id="current-rating"><!-- will show current rating --></li> 
     <span id="ratelinks"> 
     <li><a href="javascript:void(0)" title="1 star out of 5" class="one-star">1</a></li> 
     <li><a href="javascript:void(0)" title="2 stars out of 5" class="two-stars">2</a></li> 
    <li><a href="javascript:void(0)" title="3 stars out of 5" class="three-  stars">3</a></li> 
    <li><a href="javascript:void(0)" title="4 stars out of 5" class="four-stars">4</a></li> 
    <li><a href="javascript:void(0)" title="5 stars out of 5" class="five-stars">5</a></li> 
    </span> 
    </ul>
</body> 
</html>

我的 starrating.css 文件:

/* CSS Document */

.star-rating,
.star-rating a:hover,
.star-rating a:active,
.star-rating .current-rating{
background: url(star.gif) left -1000px repeat-x;
}
.star-rating{
position:relative;
width:125px;
height:25px;
overflow:hidden;
list-style:none;
margin:0;
padding:0;
background-position: left top;
}
.star-rating li{
display: inline;
}
.star-rating a,
.star-rating .current-rating{
position:absolute;
top:0;
left:0;
text-indent:-1000em;
height:25px;
line-height:25px;
outline:none;
overflow:hidden;
border: none;
}
.star-rating a:hover,
.star-rating a:active{
background-position: left bottom;
}
.star-rating a.one-star{
width:20%;
z-index:6;
}
.star-rating a.two-stars{
width:40%;
z-index:5;
}
.star-rating a.three-stars{
width:60%;
z-index:4;
}
.star-rating a.four-stars{
width:80%;
z-index:3;
}
.star-rating a.five-stars{
width:100%;
z-index:2;
}
.star-rating .current-rating{
z-index:1;
background-position: left center;
}

我的 starrating.js 文件-

// JavaScript Document
$(document).ready(function() {
    // get current rating
    getRating();
    // get rating function
    function getRating(){
        $.ajax({
            type: "GET",
            url: "update.php",
            data: "do=getrate",
            cache: false,
            async: false,
            success: function(result) {
                // apply star rating to element
                $("#current-rating").css({ width: "" + result + "%" });
            },
            error: function(result) {
                alert("some error occured, please try again later");
            }
        });
    }

    // link handler
    $('#ratelinks li a').click(function(){
        $.ajax({
            type: "GET",
            url: "update.php",
            data: "rating="+$(this).text()+"&do=rate",
            cache: false,
            async: false,
            success: function(result) {
                // remove #ratelinks element to prevent another rate
                $("#ratelinks").remove();
                // get rating after click
                getRating();
            },
            error: function(result) {
                alert("some error occured, please try again later");
            }
        });

    });
});

我的 PHP 文件:

<?php
// connect to database
$dbh=mysql_connect ("localhost", "abc", "") or die ('Cannot connect to the database');
mysql_select_db ("star",$dbh);



if($_GET['do']=='rate')
{

// do rate
rate();
}
else if($_GET['do']=='getrate')
{
// get rating
getRating();
}

// function to retrieve
function getRating(){

$sql= "select * from vote";
$result=@mysql_query($sql);
$rs=@mysql_fetch_array($result);
// set width of star
$rating = (@round($rs[value] / $rs[counter],1)) * 20; 
echo $rating;
}

// function to insert rating
function rate(){
$text = strip_tags($_GET['rating']);
$update = "update vote set counter = counter + 1, value = value +    ".$_GET['rating']."";

$result = @mysql_query($update); 
if(@mysql_affected_rows() == 0){
    $insert = "insert into vote (counter,value) values     ('1','".$_GET['rating']."')";
    $result = @mysql_query($insert); 
}
}
?>

在 PHP 文件中,它显示了上述特定的错误。

另外我想设置一个关于评级的功能,只有在网站上注册的人才能给出。

4

1 回答 1

0

@$_GET['do']而不是$_GET['do']

于 2013-09-23T13:24:26.240 回答