0

I have am creating a check function that enables me to check that data with the specific id and categoryid is already present in the database:

$fields['Occupation'] = array(3) { [0]=> string(1) "1" [1]=> string(1) "6" [2]=> string(1) "7" }

Line in question:

$occCheck = Jojo::selectQuery("SELECT * FROM {refocus_candidate_category} WHERE canid=? AND categoryid=?", array($emailCheck['id'], $fields['Occupation']));

Why am I getting this Error and how do I resolve:

Unknown column 'Array' in 'where clause'

Full Check Function:

    if($occCheck != FALSE)
    {
        Jojo::updateQuery("UPDATE {refocus_candidate_category} SET canid=?, categoryid=? WHERE canid=? AND categoryid=?", array($emailCheck['id'], $fields['Occupation']));
    }else{
        Jojo::insertQuery("INSERT INTO {refocus_candidate_category} SET canid=?, categoryid=? WHERE canid=? AND categoryid=?", array($emailCheck['id'], $fields['Occupation']));
    }
2
  • @Shades88 Why am I getting the error & how do I fix Commented Sep 20, 2012 at 18:38
  • check my answer, hope that might help Commented Sep 20, 2012 at 18:46

4 Answers 4

1

It looks $fields['Occupation'] is an array and it's going to be replaced by categoryid=>?< category ID. What about doing it step-by-step for each category make a question to the database?

OR

$occCheck = Jojo::selectQuery("SELECT * FROM {refocus_candidate_category}
                               WHERE canid=".$emailCheck['id']."
                               AND categoryid in
                                 (".implode(",",$fields['Occupation']).")");

if $emailCheck['id'] is not an array

Sign up to request clarification or add additional context in comments.

2 Comments

I get Input Array does not match ?: UPDATE refocus_candidate_category SET canid='11', categoryid=Array WHERE canid= UPDATE refocus_candidate_category SET canid=?, categoryid=? WHERE canid=? AND categoryid=? Array ( [0] => 11 [1] => Array ( [0] => 1 [1] => 6 [2] => 7 ) ) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1array(5)
Jess: SO as I wrote, use where operator IN and implode array to set of Ids
0

It's not exactly clear what you are trying to do in your queries, as you are writing these strange values SET canid=?.

But the problem you are facing is, that you are concatinating entire array in your SQL query string. try to echo an array then you will see it getting printed as Array. That's the source of your problem query gets expanded like someField=Array. Now that Array is not even in single quotes, so mysql is assuming it to be a column. Thus your error.

Remove that array($emailCheck['id'], $fields['Occupation']). And just set $emailCheck['id'], $fields['Occupation'][0]. your field['Occupation'] is and entire array so choose some as per your need.

10 Comments

Hey, I am now getting Input Array does not match ?: SELECT * FROM refocus_candidate_category WHERE canid='11' AND categoryid= SELECT * FROM refocus_candidate_category WHERE canid=? AND categoryid=? why? Also it did insert but only 1 value
it looks like that function internally does something to array arguments passed to it. then try array($emailCheck['id'], $fields['Occupation'][0])
I now get Input Array does not match ?: UPDATE refocus_candidate_category SET canid='11', categoryid='1' WHERE canid= UPDATE refocus_candidate_category SET canid=?, categoryid=? WHERE canid=? AND categoryid=? Array ( [0] => 11 [1] => 1 )
try array($emailCheck['id'], $fields['Occupation'][0], $emailCheck['id'], $fields['Occupation'][0]).... just a random guess. The reason for this guess is that, there are 4 placeholders in your sql query string. your function may be trying to replace them with input array elements. In input array we specified only 2, lets try putting 4
INSERT INTO refocus_candidate_category SET canid=?, categoryid=? WHERE canid=? AND categoryid=? Array ( [0] => 11 [1] => 8 [2] => 11 [3] => 8 ) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE canid='11' AND categoryid='8'' at line 1
|
0

Is there a specific reason you're passing an Array to the ...Query( functions rather than separate arguments? PHP is passing the one parameter through to the database - which interprets it as a string - so your query is actually searching for the word "Array" instead.

Try this instead:

$occCheck = Jojo::selectQuery("SELECT * FROM {refocus_candidate_category}".
                              " WHERE canid=? AND categoryid=?",
                              $emailCheck['id'], $fields['Occupation']);

2 Comments

I need to check if there are any occupation options that match my id - If there is I would like to insert new options else insert the lot.
I get Input Array does not match ?: SELECT * FROM refocus_candidate_category WHERE canid='11' AND categoryid= SELECT * FROM refocus_candidate_category WHERE canid=? AND categoryid=?
0

You have to make up your mind what Occupation you want to query for:

$occCheck = Jojo::selectQuery("
   SELECT * FROM {refocus_candidate_category} WHERE canid=? AND categoryid=?",
   array($emailCheck['id'], $fields['Occupation'][1]));

In this case i used occupation with index 1, and that will result in occupation 6 selected.

1 Comment

I need to check if they all are present

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.