SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Apr 2002
    Posts
    395
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Get javascript to run a query

    I have a rating system on my site where people give a rating for articles. I accomplish this using php+mysql. The down is that everytime someone clicks to rate, the page refreshes. I want people to be able to click on let's say "5 out of 5" and a query would be performed.

    This is what I have in php:

    PHP Code:
    <form method="post" action="<?php echo $PHP_SELF;?>">

    <input type="image" src="images/rate/5.gif" value="5" name="rate" >
    <input type="image" src="images/rate/4.gif" value="4" name="rate" >
    <input type="image" src="images/rate/3.gif" value="3" name="rate">
    <input type="image" src="images/rate/2.gif" value="2" name="rate">
    <input type="image" src="images/rate/1.gif" value="1" name="rate">

    </form>
    <?
    $rating 
    $_POST["rate"];
    if(isset(
    $rating))
    {
    $query "UPDATE articles SET ratednum = ratednum + 1, rating = rating + '$rating' WHERE id = '$id'";
    mysql_query($query) or die('Error, query failed');
    }
    ?>
    How can I do this query in javascript, so the page would not need be refreshed?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Addict
    Join Date
    Apr 2002
    Posts
    395
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank You


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •