SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Small problem

  1. #1
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Small problem

    I am trying to run this query

    Code PHP:
    elseif(!empty($_POST['loc']) && $mode == 'location'){
    $sql = 'SELECT a.*, u.user_id, u.username, u.user_colour from '.CLASSIFIEDS_TABLE.' a, '. USERS_TABLE .' u 
    				WHERE u.user_id = a.ad_poster_id and a.state = '. $location .' and a.ad_expire > '.time().'  ORDER BY a.ad_date DESC';
     
    }

    but it is giving me this error

    Code:
    SQL ERROR [ mysqli ]
    
    Unknown column 'AL' in 'where clause' [1054]
    
    SQL
    
    SELECT a.*, u.user_id, u.username, u.user_colour from phpbb_classifieds a, phpbb_users u WHERE u.user_id = a.ad_poster_id and a.state = AL and a.ad_expire > 1242052562 ORDER BY a.ad_date DESC LIMIT 10

    I cant figure out why it is doing this, any ideas?

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,147
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    PHP Code:
    elseif(!empty($_POST['loc']) && $mode == 'location'){
    $sql 'SELECT a.*, u.user_id, u.username, u.user_colour from '.CLASSIFIEDS_TABLE.' a, 'USERS_TABLE .' u
                    WHERE u.user_id = a.ad_poster_id and a.state = \''
    $location .'\' and a.ad_expire > '.time().'  ORDER BY a.ad_date DESC';
     

    quote strings.

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by oddz View Post
    PHP Code:
    elseif(!empty($_POST['loc']) && $mode == 'location'){
    $sql 'SELECT a.*, u.user_id, u.username, u.user_colour from '.CLASSIFIEDS_TABLE.' a, 'USERS_TABLE .' u
                    WHERE u.user_id = a.ad_poster_id and a.state = \''
    $location .'\' and a.ad_expire > '.time().'  ORDER BY a.ad_date DESC';
     

    quote strings.
    You are way to good at this stuff

    Thanks it worked perfect

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    You have to put single quotes around the alfanumeric values in your query:
    PHP Code:
    $sql "
      SELECT 
          a.*
        , u.user_id
        , u.username
        , u.user_colour 
      FROM " 
    CLASSIFIEDS_TABLE " a 
      INNER JOIN " 
    USERS_TABLE " u
      ON u.user_id = a.ad_poster_id 
      WHERE a.state = '
    $location'
      AND a.ad_expire > " 
    time() . "
      ORDER BY a.ad_date DESC
    "

    Oops, too late


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
  •