SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Location
    Wellington, NZ
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Error in mysql query when using ajax

    I have a problem with a drop down list that passes an id to a second drop down list, using the protoype js library and Ajax.Updater. The second drop down list is populated with values depending on the value passed from the first drop down list.

    So far everything works as it should, except when the mysql query is run using the variable passed by Ajax.Updater.

    Here's my javascript:

    Code JavaScript:
    var customerWidget = 
    {
     
     init:function() 
     {
      var site = document.getElementById("site");
      Core.addEventListener(site, "change", customerWidget.changeListener);
     },
     
     
     changeListener: function(event)
     {
     
      new Ajax.Updater('addresses', 'scripts/checklist-customer.php', 
      { 
     
       method: 'post',
       parameters: $('site').serialize(true)
     
      });
     
     }
     
    };
     
    Core.start(customerWidget);

    And here's the mysql_query that runs when a value is selected from the drop down list.

    PHP Code:
    $user $_POST['site'];

     
    $ads mysql_query("SELECT * FROM address 
                         LEFT JOIN addlook ON addlook.addid = address.id
                         WHERE addlook.user = 
    $user"); 
    The error I get is:

    Unknown column 'value' in 'where clause'

    where 'value' seems to be the correct value that I want passed. If I hard code that value into the sql query, it works fine.

    What have I done wrong, this is my first adventure into ajax so apologies if this is obvious.

    Thanks

    Richard.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    query looks okay (except you want INNER JOIN, not LEFT OUTER JOIN)

    is addlook.user a numeric column? if not, you'll want single quotes around the value
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Location
    Wellington, NZ
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's always so simple! It was the single quotes around $user that I was missing. It's all working now.

    Thanks for the quick reply.


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
  •