473,396 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

storing star ratings

Hi,

I need to store the star rated values in mysql. How will I do it. This is the code I have used to create the star rater,

<ul class="star-rating small-star">
<li class="current-rating" style="width:50%">Currently 2.5/5 Stars.</li>
<li><a href="#" title="1 star out of 5" class="one-star">1</a></li>
<li><a href="#" title="2 stars out of 5" class="two-stars">2</a></li>
<li><a href="#" title="3 stars out of 5" class="three-stars">3</a></li>
<li><a href="#" title="4 stars out of 5" class="four-stars">4</a></li>
<li><a href="#" title="5 stars out of 5" class="five-stars">5</a></li>
</ul>

and I need to get the rated values(like 1 star or 2 star) and store that in mysql using php. Once the user rates a picture for example 4 stars, how will I get that value into php variable and store it in mysql. I am totally new to this concept. Can anybody give me some idea.

With regards
Feb 13 '08 #1
5 2429
ronverdonk
4,258 Expert 4TB
See this little example named A.PHP.
It gives assigns a HREF link to each star rating. When the user clicks it will call itself passing the choosen rating number. In the second pass you can pick up that rating from the $_GET array and store it in the database.
NOTE!!! in order to prevent any attacks you must cleans and verify the validity of the input before storing it in the database!!
[php]<?php
// Script A.PHP

if (isset($_GET['stars'])) {
$stars=strip_tags(htmlentities($_GET['stars']));
// NOTE!!! You must cleanse and check the input before storing in the database
//
// From here you can store the value in your db
}
else {
?>
<ul class="star-rating small-star">
<li class="current-rating" style="width:50%">Currently 2.5/5 Stars.</li>
<li><a href="a.php?stars=1" title="1 star out of 5" class="one-star">1</a></li>
<li><a href="a.php?stars=2" title="2 stars out of 5" class="two-stars">2</a></li>
<li><a href="a.php?stars=3" title="3 stars out of 5" class="three-stars">3</a></li>
<li><a href="a.php?stars=4" title="4 stars out of 5" class="four-stars">4</a></li>
<li><a href="a.php?stars=5" title="5 stars out of 5" class="five-stars">5</a></li>
</ul>
<?php }
?>[/php]
Ronald
Feb 13 '08 #2
See this little example named A.PHP.
It gives assigns a HREF link to each star rating. When the user clicks it will call itself passing the choosen rating number. In the second pass you can pick up that rating from the $_GET array and store it in the database.
NOTE!!! in order to prevent any attacks you must cleans and verify the validity of the input before storing it in the database!!
[php]<?php
// Script A.PHP

if (isset($_GET['stars'])) {
$stars=strip_tags(htmlentities($_GET['stars']));
// NOTE!!! You must cleanse and check the input before storing in the database
//
// From here you can store the value in your db
}
else {
?>
<ul class="star-rating small-star">
<li class="current-rating" style="width:50%">Currently 2.5/5 Stars.</li>
<li><a href="a.php?stars=1" title="1 star out of 5" class="one-star">1</a></li>
<li><a href="a.php?stars=2" title="2 stars out of 5" class="two-stars">2</a></li>
<li><a href="a.php?stars=3" title="3 stars out of 5" class="three-stars">3</a></li>
<li><a href="a.php?stars=4" title="4 stars out of 5" class="four-stars">4</a></li>
<li><a href="a.php?stars=5" title="5 stars out of 5" class="five-stars">5</a></li>
</ul>
<?php }
?>[/php]
Ronald

Hi,
thanks for your solution. It is working, but there is some problem.
Since I am linking to same page a.php, when I click the stars it will take me to the blank page. I am using this rating star in a form where the user has to fill the next contents, but as soon as the star is clicked it directs to blank page.
How to solve this issue.

With regards
Feb 14 '08 #3
ronverdonk
4,258 Expert 4TB
Of course it gives you a blank page, that code was not complete, it was just a sample on how to do it!

You are supposed to complete the code yourself within this piece
[php]if (isset($_GET['stars'])) {
$stars=strip_tags(htmlentities($_GET['stars']));
// NOTE!!! You must cleanse and check the input before storing in the database
//
// From here you can store the value in your db
}[/php]
Ronald
Feb 14 '08 #4
Thank you

With Regards
Feb 14 '08 #5
ronverdonk
4,258 Expert 4TB
Thank you

With Regards
You are welcome any time.

Ronald
Feb 14 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jeremy Posner | last post by:
Can someone please clear up some confusion I am having on Star Transformations: I have read about the conditions for Star Transformations, especially this onen (from 9i Data Warehousing Guide): ...
14
by: Stainless | last post by:
I have a public class Globals, which obviously holds all my global data. I have an array of 243 items, currently structs of type typedef struct STAR { int x; int y; int stellar_class;...
2
by: Brian | last post by:
Hi - Does anyone know how Netflix manages its star rating system? The javascript is either computer generated or obfusicated. It's more trouble to reverse engineer than it's worth. I'm not...
2
by: Baron Samedi | last post by:
I am looking for a simple rating script whcih does not require SQL. Thanks in advance for any help.
3
by: R. Rajesh Jeba Anbiah | last post by:
I just checked the new GG Beta and came across this interesting ratings (ratings given by regulars/newbies to c.l.php regulars). I guess this might surprise for some. Poster - Avg -...
0
by: Ben Butschko | last post by:
Hi @all! I've got a little problem: I want to use a Star Rater Script (CSS Design) for an Voting Formular. http://komodomedia.com/blog/samples/ratings.htm The values can be written via...
1
by: webcm123 | last post by:
I'm looking for a good method of securing ratings. Cookies lock isn't sufficient. In addition to cookies I would need something else. I'm introducing some ways. -= Storing rates inside seperate...
4
by: MissElegant | last post by:
Hi every body I wanna find someone in here who'd create me a 5-star rating system for my website using Javascript. The script should accept the rating a user made and place a cookie on the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.