Results 1 to 3 of 3

Thread: Ajax: Coupon Code Enter Get Instant Result

  1. #1
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Ajax: Coupon Code Enter Get Instant Result

    I've set up a table in my MySQL database which has coupon codes in it. When someone signs up on my website they enter a coupon code, I want to use Ajax to give them an answer straight away if there coupon is valid or not... Is this fairly complicated? Does anyone have an example of something similar to this?

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Code:
    //mysql connection
    $code = $_POST["coupon"];
    $query = "SELECT * FROM mytable";
    $result = mysql_query($query);
    $found = false;
    for ($i = 0;$i < mysql_num_rows($result);$i++) {
       $coupon = mysql_result($result,$i,"mycolumn");
       if ($code == $coupon) {
          $found = true;
          }
       }
    if ($found == true) {
       echo "The code ".$code." was found.";
       }
    mysql_close();
    Hopefully you'll know what to edit, but that's basically how you do a mysql search.
    There is other ways, using mysql_fetch_assoc, but that can be a little more complicated.

    //EDIT: Sorry, I forgot you wanted AJAX. I missed it, but that's a PHP script
    Last edited by mburt; 04-07-2007 at 10:39 AM.
    - Mike

  3. #3
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The AJAX part is fairly simple once you get the PHP part working.

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
  •