Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php]/[mysql] dodanie danych
Forum PHP.pl > Forum > PHP
Lejto
Mam taki kod
  1. <?php
  2.  
  3. $puste = '';
  4. $zero = '0';
  5. $zero2 = '0.00';
  6. $zero3 = '0000-00-00 00:00:00';
  7. $duration = 'duration';
  8. $full = 'full';
  9.  
  10. while (($data = fgetcsv($uchwyt, 1000, ";")) !== FALSE)
  11.    {
  12.        $num = count($data);
  13.         $row;
  14.    for ($c=0; $c < $num; $c++)
  15.      {
  16.     $sql = mysql_query("INSERT INTO `legalnyprogram1`.`probid_auctions` (`name`, `description`, `picpath`, `quantity`, `auction_type`, `start_price`,
  17. `reserve_price`, `buyout_price`, `bid_increment_amount`, `duration`, `country`, `zip_code`, `shipping_method`, `shipping_int`, `payment_methods`,
  18. `category_id`, `active`, `payment_status`, `start_time_old`, `end_time_old`, `closed`, `nb_bids`, `max_bid`, `nb_clicks`, `owner_id`, `hpfeat`, `catfeat`,
  19. `bold`, `hl`, `hidden_bidding`, `currency`, `auction_swapped`, `postage_amount`, `insurance_amount`, `type_service`, `enable_swap`, `direct_payment_paid`,
  20. `addl_category_id`, `deleted`, `live_pm_amount`, `live_pm_date`, `live_pm_processor`, `shipping_details`, `hpfeat_desc`, `reserve_offer`, `reserve_offer_winner_id`,
  21. `list_in`, `close_in_progress`, `bid_in_progress`, `bank_details`, `direct_payment`, `apply_tax`, `auto_relist_bids`, `end_time_type`, `approved`, `count_in_progress`,
  22. `listing_type`, `is_offer`, `offer_min`, `offer_max`, `auto_relist_nb`,`is_relisted_item`,`start_time`,`end_time`,`creation_in_progres
  23. `,`creation_date`,`state`,`start_time_type`,`retract_in_progress`,`notif_item_re
  24. isted`,`is_draft`,`nb_offers`,
  25. `start_on_bid`,`discount`,`discount_start_date`,`discount_end_date`,`additional_
  26. ows_titles`,`additional_rows_values`,`listing_template_id`) VALUES ('".$data[3]."', '".$data[12]."','".$puste."','".$data[13]."','".$data[2]."','".$data[14]."','".$zero2."','".$data[17]."','".$zero.'","'.$data[23]."','".$puste."','".$puste."','".$data[30]."',
  27. '".$data[31]."','".$data[37]."','".$data[1]."',
  28. '".$zero."','".$puste."','".$zero3."','".$zero3."','".$zero."','".$zero."','".$zero2."','".$zero."','".$zero."','".$data[19]."','".$data[20]."','".$data[17]."','".$data[18]."',
  29. '".$zero."','".$puste."','".$zero."','".$data[32]."',
  30. '".$data[33]."','".$data[35]."','".$zero."','".$zero."','".$zero."','".$zero."','".$zero2."','".$zero."','".$puste."','".$zero2."','".$zero."','".$data[0]."','".$zero."','".$zero."',
  31. '".$puste."','".$puste."','".$zero."','".$zero."',
  32. '".$duration."','".$data[38]."','".$zero."','".$full."','".$zero."','".$zero2."','".$zero2."','".$data[29]."','".$data[28]."','".$data[21]."','".$zero."','".$zero."','".$zero."',
  33. '".$puste."','".$data[21]."','".$puste."','".$zero."',
  34. '".$data[40]."','".$zero."','".$data[22]."','".$zero."','".$zero."','".$zero."','".$data[4]."','".$data[5]."','".$zero."')");    
  35.      }
  36. ?>

tabela
  1. CREATE TABLE `probid_auctions` (
  2. `auction_id` bigint(20) NOT NULL AUTO_INCREMENT,
  3. `name` varchar(255) character SET utf8 collate utf8_unicode_ci NOT NULL,
  4. `description` longtext character SET utf8 collate utf8_unicode_ci NOT NULL,
  5. `picpath` varchar(255) character SET latin2 NOT NULL DEFAULT '',
  6. `quantity` smallint(6) NOT NULL DEFAULT '0',
  7. `auction_type` varchar(30) collate utf8_polish_ci NOT NULL,
  8. `start_price` double(16,2) NOT NULL DEFAULT '0.00',
  9. `reserve_price` double(16,2) NOT NULL DEFAULT '0.00',
  10. `buyout_price` double(16,2) NOT NULL DEFAULT '0.00',
  11. `bid_increment_amount` double(16,2) NOT NULL DEFAULT '0.00',
  12. `duration` smallint(6) NOT NULL DEFAULT '0',
  13. `country` varchar(100) character SET latin2 NOT NULL DEFAULT '',
  14. `zip_code` varchar(50) character SET latin2 NOT NULL DEFAULT '',
  15. `shipping_method` tinyint(4) NOT NULL DEFAULT '0',
  16. `shipping_int` tinyint(4) NOT NULL DEFAULT '0',
  17. `payment_methods` text collate utf8_polish_ci NOT NULL,
  18. `category_id` int(11) NOT NULL DEFAULT '0',
  19. `active` tinyint(4) NOT NULL DEFAULT '0',
  20. `payment_status` varchar(20) character SET latin2 NOT NULL DEFAULT '',
  21. `start_time_old` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  22. `end_time_old` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  23. `closed` tinyint(4) NOT NULL DEFAULT '0',
  24. `nb_bids` int(11) NOT NULL DEFAULT '0',
  25. `max_bid` double(16,2) NOT NULL DEFAULT '0.00',
  26. `nb_clicks` int(11) NOT NULL DEFAULT '0',
  27. `owner_id` int(11) NOT NULL DEFAULT '0',
  28. `hpfeat` tinyint(4) NOT NULL DEFAULT '0',
  29. `catfeat` tinyint(4) NOT NULL DEFAULT '0',
  30. `bold` tinyint(4) NOT NULL DEFAULT '0',
  31. `hl` tinyint(4) NOT NULL DEFAULT '0',
  32. `hidden_bidding` tinyint(4) NOT NULL DEFAULT '0',
  33. `currency` varchar(100) character SET latin2 NOT NULL DEFAULT '',
  34. `auction_swapped` tinyint(4) NOT NULL DEFAULT '0',
  35. `postage_amount` double(16,2) NOT NULL DEFAULT '0.00',
  36. `insurance_amount` double(16,2) NOT NULL DEFAULT '0.00',
  37. `type_service` varchar(50) collate utf8_polish_ci NOT NULL,
  38. `enable_swap` tinyint(4) NOT NULL DEFAULT '0',
  39. `direct_payment_paid` tinyint(4) NOT NULL DEFAULT '0',
  40. `addl_category_id` int(11) NOT NULL DEFAULT '0',
  41. `deleted` tinyint(4) NOT NULL DEFAULT '0',
  42. `live_pm_amount` double(16,2) NOT NULL DEFAULT '0.00',
  43. `live_pm_date` int(11) NOT NULL DEFAULT '0',
  44. `live_pm_processor` varchar(50) character SET latin2 NOT NULL DEFAULT '',
  45. `shipping_details` mediumtext collate utf8_polish_ci NOT NULL,
  46. `hpfeat_desc` text character SET latin2 NOT NULL,
  47. `reserve_offer` double(16,2) NOT NULL DEFAULT '0.00',
  48. `reserve_offer_winner_id` int(11) NOT NULL DEFAULT '0',
  49. `list_in` varchar(50) character SET latin2 NOT NULL DEFAULT 'auction',
  50. `close_in_progress` tinyint(4) NOT NULL DEFAULT '0',
  51. `bid_in_progress` tinyint(4) NOT NULL DEFAULT '0',
  52. `bank_details` text collate utf8_polish_ci,
  53. `direct_payment` text collate utf8_polish_ci,
  54. `apply_tax` tinyint(4) NOT NULL DEFAULT '0',
  55. `auto_relist_bids` tinyint(4) NOT NULL DEFAULT '0',
  56. `end_time_type` enum('duration','custom') character SET latin2 NOT NULL DEFAULT 'duration',
  57. `approved` tinyint(4) NOT NULL DEFAULT '0',
  58. `count_in_progress` tinyint(4) NOT NULL DEFAULT '0',
  59. `listing_type` enum('full','quick','buy_out') character SET latin2 NOT NULL DEFAULT 'full',
  60. `is_offer` tinyint(4) NOT NULL DEFAULT '0',
  61. `offer_min` double(16,2) NOT NULL DEFAULT '0.00',
  62. `offer_max` double(16,2) NOT NULL DEFAULT '0.00',
  63. `auto_relist_nb` tinyint(4) NOT NULL DEFAULT '0',
  64. `is_relisted_item` tinyint(4) NOT NULL DEFAULT '0',
  65. `start_time` int(11) NOT NULL DEFAULT '0',
  66. `end_time` int(11) NOT NULL DEFAULT '0',
  67. `creation_in_progress` tinyint(4) NOT NULL DEFAULT '0',
  68. `creation_date` int(11) NOT NULL DEFAULT '0',
  69. `state` varchar(100) character SET latin2 NOT NULL DEFAULT '',
  70. `start_time_type` enum('now','custom') character SET latin2 NOT NULL DEFAULT 'now',
  71. `retract_in_progress` tinyint(4) NOT NULL DEFAULT '0',
  72. `notif_item_relisted` tinyint(4) NOT NULL,
  73. `is_draft` tinyint(4) NOT NULL,
  74. `nb_offers` int(11) NOT NULL,
  75. `start_on_bid` tinyint(1) NOT NULL,
  76. `discount` int(11) NOT NULL DEFAULT '0',
  77. `discount_start_date` int(11) NOT NULL,
  78. `discount_end_date` int(11) NOT NULL,
  79. `additional_rows_titles` text collate utf8_polish_ci NOT NULL,
  80. `additional_rows_values` text collate utf8_polish_ci NOT NULL,
  81. `listing_template_id` smallint(6) NOT NULL,
  82. PRIMARY KEY (`auction_id`),
  83. KEY `stats_drafts` (`is_draft`,`owner_id`),
  84. KEY `user_auctions` (`owner_id`,`closed`,`deleted`,`creation_in_progress`,`is_draft`),
  85. KEY `mb_auctions_id` (`deleted`,`owner_id`,`closed`,`creation_in_progress`,`auction_id`),
  86. KEY `user_auctions_end_time` (`closed`,`owner_id`,`end_time`,`deleted`,`creation_in_progress`,`is_draft`),
  87. KEY `auctions_start_time` (`active`,`approved`,`deleted`,`closed`,`creation_in_progress`,`start_time`),
  88. KEY `auctions_nb_bids` (`active`,`approved`,`deleted`,`closed`,`creation_in_progress`,`nb_bids`),
  89. KEY `auctions_max_bid` (`active`,`approved`,`deleted`,`closed`,`creation_in_progress`,`max_bid`),
  90. KEY `auctions_start_price` (`active`,`approved`,`deleted`,`closed`,`creation_in_progress`,`start_price`),
  91. KEY `auctions_name` (`active`,`approved`,`deleted`,`closed`,`creation_in_progress`,`name`),
  92. KEY `auctions_end_time` (`active`,`approved`,`deleted`,`closed`,`creation_in_progress`,`end_time`),
  93. KEY `hp_featured` (`hpfeat`,`active`,`approved`,`closed`,`creation_in_progress`,`deleted`),
  94. KEY `cat_featured` (`catfeat`,`active`,`approved`,`closed`,`creation_in_progress`,`deleted`),
  95. FULLTEXT KEY `name` (`name`),
  96. FULLTEXT KEY `description` (`description`),
  97. FULLTEXT KEY `zip_code` (`zip_code`)
  98. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci PACK_KEYS=0 COMMENT='Table with auctions details' AUTO_INCREMENT=1 ;

przy wywołaniu kodu otrzymuje
Kod
Column count doesn't match value count at row 1Column count doesn't match value count at row 1Column count doesn't match value count at row 1

nie wiem zupełnie gdzie mogę mieć błąd ;/

Pozdrawiam
osl
gdzieś w zapytaniu tongue.gif

szybki test znajdź/zamień w edytorze i wyszło mi że kolumn masz o 2 mniej niż w danych (VALUES).
Nie wiem na ile to wiarygodne, ale zgadzałoby się z errorem.
WebCM
Liczba wartości dla pól w zapytaniu jest inna niż liczba wymienionych kolumn. Poza tym polecam predefiniowane zapytania - przekazywanie danych jest bezpieczniejsze. Łatwiej też zorientować się, czy dla każdego pola podajesz wartość.
  1. <?php
  2. $q = $db->prepare('zapytanie');
  3. $q -> execute(array('pole' => 'wartosc', ...));
  4. ?>
Lejto
rzeczywiście poprawiałem zapytanie winksmiley.jpg i śmiga jeszcze wywaliłem zbędne pola w których wartość jest domyśla, szkoda że nie zrobiłem tego wcześniej...
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.