Batch add data in php
Next we will test a php code to add cities in batches and separate them with "|.
Function Addtype ()
{
If ($ _ FILES) {exit ;}
$ Info = '';
$ Cityname = trim (PostGet ('cityname', 1 ));
$ Citytype = trim (PostGet ('citytype', 1 ));
$ Orderid = trim (PostGet ('orderid', 1 ));
If ($ cityname = 0 |! Is_numeric ($ cityname ))
{
MessAge ('select a city ');
}
Elseif (strlen ($ citytype) <2)
{
MessAge ('input city Region ');
}
Elseif (! Is_numeric ($ orderid ))
{
MessAge ('Sorry, the order must be a number! ');
}
If (strpos ($ citytype, '| ')! = False)
{
$ Array = explode ('|', $ citytype );
If (is_array ($ array ))
{
$ Array = array_filter ($ array, 'filter ');
}
}
Else
{
$ Array = $ citytype;
}
$ Db = new Db ();
$ D = date ("Y-m-d ");
If (is_array ($ array ))
{
Foreach ($ array as $ v =>$ _ v)
{
$ Row = $ Db-> query ("Select * from 111cn_city where upid = $ cityname and cntitle =" ". $ _ v .""");
If ($ Db-> rows ($ row ))
{
$ Info. = $ _ v .',';
}
Else
{
Try {
$ Db-> query ("Insert into 111cn_city (cntitle, upid, orderid, createdate) values ('$ _ V', $ cityname,' $ orderid ',' $ D ') ");
} Catch (Exception $ e ){
MessAge ('Operation failed! ');
}
}
}
MessAge ("added successfully, failed $ info", 'addtype. php ');
}
Else
{
$ Query = $ Db-> query ("select * from 111cn_city where upid = $ cityname and cntitle =" $ array "");
If ($ Db-> rows ($ Query ))
{
MessAge ("sorry, the City [$ array] You want to add already has a database ");
}
Else
{
Try {
$ Db-> query ("Insert into 111cn_city (cntitle, upid, orderid, createdate) values ('$ array', $ cityname,' $ orderid', '$ D ') ");
MessAge ('Operation succeeded ', 'addtype. php ');
} Catch (Exception $ e ){
MessAge ('failed successfully ');
}
}
}
}
Original site reprinted with www.111cn.cn