Connecting to a MySQL database with AJAX

Discussion in 'Programming' started by Gugel, May 5, 2008.

  1. #1
    I'm trying to get a dynamic promotional code system to work. Basically, the AJAX is validating the promotional code by comparing what the customer typed with a MySQL database. The discount rate is currently set to 20%, but I'm trying to make it more dynamic. I added a field to the MySQL database called "discount" and now I want to reference that field in AJAX. Here is the code I am working with:

    if(responseText == "Valid")
    {
    cost = cost - (cost * 0.20)
    cost = parseInt((cost)*100)/100;
    document.getElementById('purchaseprice').value = cost;
    document.getElementById('pricediv').innerHTML = "$"+cost;
    divobj.style.color="##006600";
    divobj.innerHTML=xmlHttp.responseText;
    }

    So basically, instead of: cost = cost - (cost * 0.20)
    I want cost = cost - (cost * discount)

    How do I define the discount variable in AJAX so it references that field in the MySQL table?

    Thanks guys!
     
    Gugel, May 5, 2008 IP
  2. apmsolutions

    apmsolutions Peon

    Messages:
    66
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'm not quite sure if I follow, but why couldn't you replace the 0.20 with the variable that stores the discount amount from the database?

    Not sure what language you are using.
     
    apmsolutions, May 5, 2008 IP
  3. Gugel

    Gugel Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This has been resolved. Thank you guys.
     
    Gugel, May 5, 2008 IP