Basically I have a dynamic form which provides a variable number of inputs depending on how the user selects that, I have set all text inputs with this name="user[]" to store the values into an array.
I then after submission of form place into this array:
$array = check_input($_POST['user']);
I am then using this array in a query like so:
$query = 'SELECT * FROM users_tb WHERE student_number IN(' . implode(',', $array) .')';
mysql_query($query) or die(mysql_error());
$result=mysql_query($query);
and I get this error:
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 1
Now i wanted to check also values are in the array, but when i try print_r($array); to see if the values are there it just prints the word "Array"
what am I doing wrong here?
thanks
ADDITIONAL PROBLEM ----
I have an array strings inputted by the user in a different dynamic form. I want to store each value in the array into a table along with an itemid (which is the same for all)
My query is currently inserting the whole array into one rows text_value with implode. Is there a way instead of looping through the array and running a query for each value in the array, for me to do this?
current query:
$query = "INSERT INTO answers_tb (item_id, text_value)VALUES('$itemid','".implode(',', $answers) . "')";
here is print_r of array:
Array ( [0] => option 1 [1] => option 2 [2] => option 3 [3] => option 4 )
thanks