Little Help Needed.. ajax JS + mysql

Discussion in 'Programming' started by hasbehas, Mar 15, 2008.

  1. #1
    I am rying to modify a free maillist script.
    trying to add name + country fields.

    in php file (inserts to DB)
    
          // Connect to database
          $con = mysql_connect(DBHOST ,DBUSER, DBPASS);
          mysql_select_db(DBNAME, $con);
          // Insert email address into mailinglist table 
          $result = mysql_query("INSERT INTO mailinglist SET email='" . $address . "'");
          if(mysql_error()){
            $message = "<strong>Error</strong>: There was an error storing your email address.";
          }
          else {
            $message = "Thanks for signing up!";
          }
    PHP:
    and in js file
    
    function storeAddress(e) {
      // Update user interface
      $('response').innerHTML = 'Adding email address...';
      // Prepare query string and send AJAX request
      var pars = 'address=' + escape($F('address')) ;
      
      var myAjax = new Ajax.Updater('response', 'ajaxServer.php', {method: 'get', parameters: pars});
      // Stop form from submitting when JavaScript is enabled
      Event.stop(e);
    }
    
    Code (markup):

    I need to add $name and $country fields. I tried , but couldnt.. (I have already added them to mysql table, also form field)

    Thanks
     
    hasbehas, Mar 15, 2008 IP
  2. krzyk

    krzyk Peon

    Messages:
    61
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'm not sure what libraries you use, I would try changing 1 line in the php part and 1 line in js one. Here it goes.

    php:
    $result = mysql_query("INSERT INTO mailinglist SET email='" . $address . "', name='" . $name . "', country='" . $country);
    PHP:
    js:
    var pars = 'address=' + escape($F('address')) + '&name=' + escape($F('name')) + '&country=' + escape($F('country')) ;
    Code (markup):
     
    krzyk, Mar 16, 2008 IP
  3. hasbehas

    hasbehas Well-Known Member

    Messages:
    726
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    190
    #3
    Thanks.. I will try these, :)
     
    hasbehas, Mar 16, 2008 IP