开发者

how can i insert the array of id into a single field of data base

hi how can i insert the array of service id into table into a single field like 2,3,4 in database i am confuse please help followingis my code...i am using this but it is inserted only single id..

$service=implode(",",$_POST['service']);

$sqlQuery="INSERT INTO ".DBPROMOTION." SET 
            promotion_service_id='".$service."', 
            promotion_user_id='".$user."', 
            promotion_discount='".$_POST['discount'].$_POST['type']."',
            promotion_title='".$_POST['title']."',
            promotion_start_dat开发者_开发知识库e='".$startDate."', 
            promotion_end_date='".$endDate."', 
            promotion_code='".$_POST['code']."', 
            promotion_description='".$_POST['desc']."'"


You should use two database tables with relation one-to-many to link more than one element with table columnt. That would be better design.

You may insert all id's into db in form of string, but I don't think, that is what you aiming for.

Also, you should sanitize your input from $_POST before entering int to db, to prevent sql injection.


you database-model seem to be not normalized - correct that first before programming an application that will cause some realy big problems in the future.

also, you should never insert posted data directly to avoid sql-injection. use mysql_real_escape_string or, better, PDO for prepared statements.

to your problem directly: i think 'promotion_service_id' is an integer-field - '2,3,4' is a string, so (fortunately) you have no chance to insert it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜