954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problem using MYSQL IN function with PHP array

Hi there,

I have a form that collects array values and then posts it to another page.eg

<form action="page2" method="POST">
<input name = "myid[]" type="text" value="1">
<input name = "myid[]" type="text" value="4">
<input name = "myid[]" type="text" value="6">
</form>


the second page then receives the array and implodes the results

$i = $_POST['myid[]'];
$j = implode(",",$i);


i then want the $j to be used to filter a table with the MYSQL IN statement

$col1_items = $j;
mysql_select_db($mydb, $myconnection);
$query_items = sprintf("SELECT * FROM myshop WHERE pkId IN (%s), GetSQLValueString($col1_items, "text"));
$items = mysql_query($query_items, $myconnection) or die(mysql_error());


but for some reason this does not work. Any ideas

opticblaze
Newbie Poster
6 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

Solved this one. The problem was that i used the GetSQLValueString to escape the sql as text. Mysql did not like this. When i changed the statement to not include GetSQLValueString it worked.

$col1_items = $j;
mysql_select_db($mydb, $myconnection);
$query_items = sprintf("SELECT * FROM myshop WHERE pkId IN ($col1_items));
$items = mysql_query($query_items, $myconnection) or die(mysql_error());
opticblaze
Newbie Poster
6 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: