|
Posted by Black Shuck on 02/08/06 01:06
On Mon, 06 Feb 2006 04:01:33 -0000, noone <noone@nowhere.com> wrote:
> Black Shuck wrote:
>> I have a form on a PHP page, to add entries to a MySQL database. I
>> have the simple string fields working fine, but I am having trouble
>> with a multiple select listbox filling a MySQL ENUM type.
>> I have assigned my values in the listbox, to match the ENUM values,
>> and if I add a dump_var of the value of listbox posted to the PHP
>> code, it looks sensible:
>> array(3) { [0]=> string(1) "0" [1]=> string(1) "2" [2]=> string(1) "4"
>> }
>> The problem is, how do I parse this into a format I can pass into the
>> MySQL query for the ENUM field?
>> Can some nice person give a newbie a clue? I figure this must be a
>> common thing to do...
>
>
> My reading of the docs on the datatype of ENUM column is tat it is not
> to be confused with storing an entire array into a single column.
>
> An ENUM column is not magic.. it is a datatype that is analogous to a
> column in say.. Oracle that has a check constraint. --make sure that
> data stored in this column is equal to x,y,z - and whether or not the
> column accepts NULL values or not.
>
> Not knowing what you are doing or how you have designed the db etc...
> extract the data from the array and store them as seperate records
> (based on what you have given us so far...)
>
> (Progamming exact syntax left to the OP as an exercise)
>
> while( list($key, $val) = each( $array ) ) {
> ...insert into tableA (col1,col2,enumcol)
> values ($col1,$col2,$val)...
> }
>
> If the value being stored in the enum column is not what you enumerated,
> your insert should fail and you should execute a rollback statement and
> handle the error so that the "poster" can correct the erroneous data. If
> you are using drop down list limiting the values to x,y,z then
> theoretically that should never happen ---- I would still VALIDATE ALL
> FORM data for sqlinjection BEFORE inserting/deleting/querying the db....
> etc..
>
> M.
??? I have no idea what this all means :-(
All I know, is the form post data looks like this:
array(3) { [0]=> string(1) "0" [1]=> string(1) "2" [2]=> string(1) "4" }
and I need to pass: "0,2,4" into my SQL query.. So, in simpleton terms,
what do I need to do?
Navigation:
[Reply to this message]
|