Web Analytics Made Easy -
StatCounter Can you see anything wrong? - CodingForum

Announcement

Collapse
No announcement yet.

Can you see anything wrong?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can you see anything wrong?

    I'm having some problems with this query. Can anyone see what the problem is?

    Code:
    $query = "SELECT * FROM $dbselect WHERE $column = $selected ORDER BY id ASC";
    Here is the error I get...
    Code:
    selected = Tester
    column = lastname
    dbselect = shipping
    Error:Unknown column 'Tester' in 'where clause'
    I just echo the variables to make sure they are coming over. Otherwise, I don't see what is wrong with that statement. I've even enclosed the variables in single quotes. Here is what I've tried so far....

    Code:
    $query = "SELECT * FROM ".$dbselect." WHERE ".$column."=".$selected." ORDER BY id ASC";
    $query = "SELECT * FROM $dbselect WHERE ($column = $selected) ORDER BY id ASC";
    Where I do this one ...
    Code:
    $query = "SELECT * FROM $dbselect WHERE '$column = $selected' ORDER BY id ASC";
    I don't get an error, the table shows up, but it doesn't show any results. Any idea on whats going on?

  • #2
    Code:
    $query = "SELECT * FROM `$dbselect` WHERE `$column` = '$selected' ORDER BY `id` ASC";
    Forget style. Code to semantics. Seperate style from structure, and structure from behaviour.
    I code to specs, and test only in Firefox (unless stated otherwise).

    Comment


    • #3
      Thanks, that worked.

      Comment

      Working...
      X