在WordPress中将CSV导入数据库

时间:2017-08-23 21:12:33

标签: php wordpress

在下面的代码中,我尝试从Word导入到WordPress中的数据库。 插入数据但我收到此错误

WordPress database error: []
INSERT INTO wp_trav_accommodation_vacancies (date_from, date_to, accommodation_id, room_type_id, rooms, price_per_room, price_per_person) VALUES ('2017-08-30', '2017-09-10', '1', '1', '3', '600.00', '0.00')

这是我运行的代码:

global $wpdb;
    if(isset($_POST["submit"]))
    {
        $file = $_FILES['file']['tmp_name'];
        $handle = fopen($file, "r");
        $c = 0;
        while(($filesop = fgetcsv($handle, 1000, ",")) !== false) {
            $date_from = $filesop[0];
            $date_to = $filesop[1];
            $accommodation_id = $filesop[2];
            $room_type_id = $filesop[3];
            $rooms = $filesop[4];
            $price_per_room = $filesop[5];
            $price_per_person = $filesop[6];



            $sql = "INSERT INTO wp_trav_accommodation_vacancies (date_from, date_to, accommodation_id, room_type_id, rooms, price_per_room, price_per_person) VALUES ('$date_from', '$date_to', '$accommodation_id', '$room_type_id', '$rooms', '$price_per_room', '$price_per_person')";

            if ($wpdb->query($sql) === TRUE) {
                echo "You database has imported successfully";
            } else {
                echo $wpdb->print_error();
                my_print_error();
            }
        }

    }

任何人都可以说出错了吗?

0 个答案:

没有答案