You are here: Re: Newbie problems with Multiple Select form, and MySQL ENUM types. « PHP Programming Language « IT news, forums, messages
Re: Newbie problems with Multiple Select form, and MySQL ENUM types.

Posted by noone on 02/06/06 06:01

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.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация