Web Analytics Made Easy -
StatCounter my mysql_query syntax is faulty, don't know correct way - CodingForum

Announcement

Collapse
No announcement yet.

my mysql_query syntax is faulty, don't know correct way

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

  • my mysql_query syntax is faulty, don't know correct way

    I am doing a query on a table as follows:

    function get_chapter_details(){

    return mysql_query("
    SELECT
    city,
    state,
    leader,
    membership,
    mission_count,
    creation_date
    FROM
    chapters
    WHERE
    id = " . addslashes($_GET['id']));

    }

    this works fine, but now I want to add another requirement in the WHERE section.

    I am doing the following:

    function get_chapter_details(){

    return mysql_query("
    SELECT
    city,
    state,
    leader,
    membership,
    mission_count,
    creation_date
    FROM
    chapters
    WHERE
    id = " . addslashes($_GET['id']) AND state = '". addslashes($_GET['state'])."');

    }

    And I'm getting the error:

    Parse error: parse error, unexpected '=' in /xxx/includes/users.php on line 26

    Of course, line 26 is

    id = " . addslashes($_GET['id']) AND state = '". addslashes($_GET['state'])."');

    Any ideas as to how I can make this work?

    Thank you in advance.

  • #2
    I figured it out. It should be:

    function get_chapter_details() {

    $query = "
    SELECT
    city,
    state,
    leader,
    membership,
    mission_count,
    creation_date
    FROM
    chapters
    WHERE
    id = '" . addslashes($_GET['id']) . "' AND
    state = '" . addslashes($_GET['state']) . "'";

    return mysql_query($query);
    }

    Comment

    Working...
    X