473,661 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

storing star ratings

59 New Member
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 2445
ronverdonk
4,258 Recognized Expert Specialist
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_ta gs(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?sta rs=1" title="1 star out of 5" class="one-star">1</a></li>
<li><a href="a.php?sta rs=2" title="2 stars out of 5" class="two-stars">2</a></li>
<li><a href="a.php?sta rs=3" title="3 stars out of 5" class="three-stars">3</a></li>
<li><a href="a.php?sta rs=4" title="4 stars out of 5" class="four-stars">4</a></li>
<li><a href="a.php?sta rs=5" title="5 stars out of 5" class="five-stars">5</a></li>
</ul>
<?php }
?>[/php]
Ronald
Feb 13 '08 #2
gubbachchi
59 New Member
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_ta gs(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?sta rs=1" title="1 star out of 5" class="one-star">1</a></li>
<li><a href="a.php?sta rs=2" title="2 stars out of 5" class="two-stars">2</a></li>
<li><a href="a.php?sta rs=3" title="3 stars out of 5" class="three-stars">3</a></li>
<li><a href="a.php?sta rs=4" title="4 stars out of 5" class="four-stars">4</a></li>
<li><a href="a.php?sta rs=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 Recognized Expert Specialist
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_ta gs(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
gubbachchi
59 New Member
Thank you

With Regards
Feb 14 '08 #5
ronverdonk
4,258 Recognized Expert Specialist
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
2278
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): "A prerequisite of the star transformation is that there be a single-column bitmap index on every join column of the fact table. These join columns include all foreign key columns" Does this mean every join column in a particular query, or...
14
4936
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; }t_star;
2
1864
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 very interested in their particular solution for rating movies - I'm not in the business - but I'd like to know the data transfer mechanism behind it. It looks like they found a solid way of moving data between client and server without getting...
2
2310
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
1752
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 - No. of ratings --------------------------------------------- Chung Leong - 4/5 - 46 ratings Jerry Stuckle - 3/5 - 175 ratings Andy Hassal - 5/5 - 15 ratings R. Rajesh Jeba Anbiah - 4/5 - 9 ratings
0
2201
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 javascript (on Click(); ) to a (hidden) formfield to transport it to another page and store the value with php into a mysql database.
1
1799
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 tables =- Seperate tables (artrates, filerates, imgrates) will contain: ID of item | rate | user | IP 1 rate = 1 record. Field USER will filled if only registered users can
4
3523
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 computer to remember what rating the user made. More than 10 of them should work on one page as well! Please help me. PS: Only use javascript and html of course.
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8542
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7362
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2760
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1740
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.