Batch add data in php

Source: Internet
Author: User

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
 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.