Note that there are some explanatory texts on larger screens.

plurals
  1. POAssistance with the following five star rating script
    text
    copied!<p>Here the JavaScript and CSS are running smooth. but whenever I try to run the PHP file it shows an error stating undefined index like following:</p> <pre><code>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 </code></pre> <p>my html code is:</p> <pre><code> &lt;html&gt; &lt;head&gt; &lt;script src="rating/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="rating/starrating.js" type="text/javascript"&gt;&lt;/script&gt; &lt;link href="rating/starrating.css" rel="stylesheet" type="text/css" media="screen" /&gt; &lt;/head&gt; &lt;body&gt; &lt;h2&gt;Star Rater&lt;/h2&gt; &lt;ul class='star-rating'&gt; &lt;li class="current-rating" id="current-rating"&gt;&lt;!-- will show current rating --&gt;&lt;/li&gt; &lt;span id="ratelinks"&gt; &lt;li&gt;&lt;a href="javascript:void(0)" title="1 star out of 5" class="one-star"&gt;1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="javascript:void(0)" title="2 stars out of 5" class="two-stars"&gt;2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="javascript:void(0)" title="3 stars out of 5" class="three- stars"&gt;3&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="javascript:void(0)" title="4 stars out of 5" class="four-stars"&gt;4&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="javascript:void(0)" title="5 stars out of 5" class="five-stars"&gt;5&lt;/a&gt;&lt;/li&gt; &lt;/span&gt; &lt;/ul&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>My starrating.css file:</p> <pre><code>/* 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; } </code></pre> <p>my starrating.js file-</p> <pre><code>// 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()+"&amp;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"); } }); }); }); </code></pre> <p>My PHP file:</p> <pre><code>&lt;?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); } } ?&gt; </code></pre> <p>In the PHP file it shows the particular above mentioned errors.</p> <p>Also I would like to set a function regarding the rating would be given by only those who are registered on the site.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload