Hi,
It will never work this way. MySQL has no knowledge of the php variable 
$categoriesIN

you can try something like this:

<?
$sql4="INSERT INTO temp (example) values ";
for( $ii = 0 ; $ii < count($categoriesIN) ; $ii++ ){
  if($ii)$sql4.=",";
  $sql4.="( ".$categoriesIN[$ii].")";
}
$result4 = mysql_query( $sql4, $db);
?>

And you should always sanitize the input from forms - the above example is 
just to show you how this works. You should check all the values in 
$categoriesIN whether they are the ones you are expecting from the form.

Hope this helps
Dobromir Velev
WebSitePulse


On Monday 23 February 2009 17:25, PJ wrote:
> I think this is a tough one... and way above my head:
> PLEASE READ ALL OF THE ABOVE TO UNDERSTAND WHAT I AM TRYING TO DO.
> Having a bit of a rough time figuring out how to formulate php-mysql to
> insert data into fields using a multiple dropdown box in a form.
>
> to post I am using the following:
> snip...
> $categoriesIN = $_POST["categoriesIN"];
>
> ...snip...
>
> <select name="$categoriesIN[]" multiple="multiple">
>       <OPTION>Choose Categories...</option>
>               <OPTION VALUE="<? echo $categoriesIN; ?>">1
>               <OPTION VALUE="<? echo $categoriesIN; ?>">2
>               <OPTION VALUE="<? echo $categoriesIN; ?>">3
>               <OPTION VALUE="<? echo $categoriesIN; ?>">4
>               <OPTION VALUE="<? echo $categoriesIN; ?>">5
>       </SELECT>
>
> ...snip...
>
> $sql4 = "FOR ( $ii = 0 ; $ii < count($categoriesIN) ; $ii++ )
>       INSERT INTO temp (example) $categoriesIN[$ii]" ;
>       $result4 = mysql_query($sql4, $db);
> ...snip
>
> this does not work! The other posts work like a charm... but this...
>
> I cannot figure out what I should be entering where... I have tried several
> different configurations, but nothing seems to work...
>
> I found this as a model for entering the selections but can't figure out
> how to modify it for my needs:
>
> <select name="branch_no[]" multiple="multiple" size="5">
> <option > Choose your location(s) </option>
> <option value="3100">3100</option>
> <option value="3105">3105</option>
> <option value="3503"> 3503</option>
> <option value="3504"> 3504</option>
> </select>
>
> What I would like to do is something like the following:
> <select name="$categoriesIN[]" multiple="multiple">
>       <OPTION>Choose Categories...</option>
>               <OPTION VALUE="1">History
>               <OPTION VALUE="2">Temples
>               <OPTION VALUE="2">Pharaohs and Queens
>               <OPTION VALUE="4">Cleopatra
>               <OPTION VALUE="4">Mummies
>       </SELECT>
> and going further, I would like to be able to use a table that actually
> holds these values to feed them to the code above. I am sure this is
> possible but it must take some huge knowledge and experience to do it.
>
> BUT ...
> as I look at things, I am wondering if the FOR statement in the above
> should be used to do several INSERTs, that is, one $sql(number) per
> selected category... now, would that require many $sqls or many INSERTs
> within the $sql ?
>
>
> --
>
> Phil Jourdan --- p...@ptahhotep.com
>    http://www.ptahhotep.com
>    http://www.chiccantine.com

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql?unsub=arch...@jab.org

Reply via email to