Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7802505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:17:08+00:00 2026-06-02T01:17:08+00:00

I have been reading through, testing, and coming up short from understanding how to

  • 0

I have been reading through, testing, and coming up short from understanding how to create a MySQL statement that matches a column against an array of values…

Here’s what I have…

<form id="form" action="index.php" method="post">
<?
$query = "SELECT Interest FROM Interests";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result))
{
    echo '<input type="checkbox" name="Interest[]" value="' . $row['Interest'] . '" /> ' . $row['Interest'] . '<br />';
}
?>
<input id="Search" name="Search" type="submit" value="Search" />
</form>

<?
if (isset($_POST['Search']))
{
    $InterestMatches = implode(',', $_POST['Interest']);
    $query = "SELECT MemberID FROM MemberInterests WHERE Interest IN ( $InterestMatches )";
    $result = mysql_query($query) or die(mysql_error());
    if (!$result) {
        $message  = 'Invalid query: ' . mysql_error() . "\n";
        $message .= 'Whole query: ' . $query;
        die($message);
    }
    while ($row = mysql_fetch_assoc($result))
    {
        $ResultingMemberIDs[] += $row['MemberID'];
    }
}
?>

And what I always get is the same error…

Unknown column 'WhateverInterest' in 'where clause'

Can someone please tell me what I am doing wrong, what I need to do to correct this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:17:10+00:00Added an answer on June 2, 2026 at 1:17 am

    I suggest echoing out your query, it’ll help with debugging. Your query currently looks like:

    SELECT MemberID FROM MemberInterests WHERE Interest IN (WhateverInterest,Testing)
    

    As you can see, in the IN the values are unquoted, so they’re interpreted as field names. You need to add quotes around each value in the IN.

    You can fix it by looping, and adding quotes around each value:

    foreach($_POST['Interest'] as &$intrest){
        $intrest = "'$intrest'";
    }
    $InterestMatches = implode(',', $_POST['Interest']);
    

    Or by imploding with "','", and then adding quotes before and after:

    $InterestMatches = "'" . implode("','", $_POST['Interest']) . "'";
    

    P.S. You should mysql_real_escape_string each value in $_POST['Interest'] to avoid SQL injections.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been reading through the forums that it is not possible to send
I have been reading through the specification of openGL 1.5, and saw that any
I have been reading through this wonderful website regarding the recommended Python IDEs and
I have been reading through the documentation on the JavaScriptMVC framework and it looks
I have been reading through lots of Q&A everywhere and these stackoverflow posts seem
I have been reading through what seems to be a good tutorial on rest
I have been reading through a few articles on PDO and they seem to
I've been reading through a number of Emacs Lisp packages and have come across
I have been reading a lot about test-driven development and decided that I want
I have been reading through several websites and even used NVIDA's code as a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.