storing star ratings

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gubbachchi
    New Member
    • Jan 2008
    • 59

    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
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #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_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

    Comment

    • gubbachchi
      New Member
      • Jan 2008
      • 59

      #3
      Originally posted by ronverdonk
      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

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        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

        Comment

        • gubbachchi
          New Member
          • Jan 2008
          • 59

          #5
          Thank you

          With Regards

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            Originally posted by gubbachchi
            Thank you

            With Regards
            You are welcome any time.

            Ronald

            Comment

            Working...