$wpdb用于插入html表单信息

时间:2015-12-14 作者:Sean McVey

我正在尝试从表单中插入已发布的变量。当我缩短插入的变量数量时,它有时会传递mysql数据库中的信息。一旦我继续添加要添加到数据库的信息,它就不会传入任何信息。我也相信有更好的方法可以做到这一点,但我还没有想出办法。

<?php
global $wpdb; 

$tablename="association";
If($_POST[\'submit\']) {

$wpdb->insert($tablename, array(

    \'association_name\' => $_POST[\'legalName\'],
    \'association_url\' => $_POST[\'url\'],
    \'association_state\' => $_POST[\'state\'],
    \'association_city\' => $_POST[\'city\'],
    \'association_zip\' => $_POST[\'zip\'],
    \'boardmember_fname\' => $_POST[\'firstName\'], 
    \'boardmember_lname\' => $_POST[\'lastName\'],
    \'boardmember_title_president\' => $_POST[\'president\'],
    \'boardmember_title_vice_president\' => $_POST[\'vicePresident\'],
    \'boardmember_title_treasurer\' => $_POST[\'treasurer\'],
    \'boardmember_title_secretary\' => $_POST[\'secretary\'],
    \'boardmember_title_director\' => $_POST[\'director\'],
    \'boardmember_title_association_manager\' => $_POST[\'propertyManager\'],
    \'boardmember_email\' => $_POST[\'email\'],
    \'association_management\' => $_POST[\'management\'],
    \'association_onsite\' => $_POST[\'onsite\'],
    \'association_master\' => $_POST[\'master\'],
    \'association_sales_price\' => $_POST[\'averageSales\'],
    \'association_age_restriction\' => $_POST[\'ageRestriction\'],
    \'association_homes\' => $_POST[\'homes\'],
    \'association_anticipated_construction\' => $_POST[\'anticipatedConstruction\'],
    \'association_end_construction\' => $_POST[\'endConstruction\'],
    \'association_pets\'=> $_POST[\'pet\'],
    \'association_description\'=> $_POST[\'description\'],
    \'association_images\'=> $_POST[\'pic\'],
    \'clubhouse_rental\' => $_POST[\'rentable\'],
    \'clubhouse_billiards\' => $_POST[\'billards\'], //Not spelt correctly 
    \'clubhouse_card_room\' => $_POST[\'cardroom\'],
    \'clubhouse_exercise_room\' => $_POST[\'exerciseroom\'],
    \'clubhouse_fireplace\' => $_POST[\'fireplace\'],
    \'clubhouse_hot_tub\' => $_POST[\'hottub\'],
    \'clubhouse_kitchen\' => $_POST[\'kitchen\'],
    \'clubhouse_library\' => $_POST[\'library\'],
    \'clubhouse_locker_rooms\' => $_POST[\'lockerrooms\'],
    \'clubhouse_music_system\' => $_POST[\'musicsystems\'],
    \'clubhouse_outdoor_deck_patio\' => $_POST[\'outdoordeckpatio\'],
    \'clubhouse_sauna\' => $_POST[\'sauna\'],
    \'clubhouse_showers\' => $_POST[\'showers\'],
    \'clubhouse_social_directors\' => $_POST[\'socialdirectors\'],
    \'clubhouse_steam_room\' => $_POST[\'steamroom\'],
    \'clubhouse_tv\' => $_POST[\'tv\'],
    \'clubhouse_wireless_internet\' => $_POST[\'wirelessinternet\']
    \'style_cape\' => $_POST[\'cape\'],
    \'style_colonial\' => $_POST[\'colonial\'],
    \'style_cottage\' => $_POST[\'cottage\'],
    \'style_georgian\' => $_POST[\'georgian\'],
    \'style_half_duplex\' => $_POST[\'halfduplex\'],
    \'style_high_rise\' => $_POST[\'highrise\'],
    \'style_low_rise\' => $_POST[\'lowrise\'],
    \'style_mid_rise\' => $_POST[\'midrise\'],
    \'style_single_family_home\' => $_POST[\'singlefamilyhome\'],
    \'style_townhouse\' => $_POST[\'townhouse\'],
    \'storage_in_unit\' => $_POST[\'inUnit\'], 
    \'storage_building_assigned\' => $_POST[\'buildingAssignedArea\'],
    \'storage_fcfs\' => $_POST[\'firstCome\'],
    \'trash_individual_bins\' => $_POST[\'individualBins\'], 
    \'trash_community_bins\' => $_POST[\'communityBins\'],
    \'trash_chutes\' => $_POST[\'trashChutes\'],
    \'trash_compactor\' => $_POST[\'compactor\'],
    \'security_cameras\' => $_POST[\'cameras\'],
    \'security_gate\' => $_POST[\'gate\'],
    \'security_fencing\' => $_POST[\'fencing\'],
    \'security_secured_hallways\' => $_POST[\'securedHallways\'],
    \'security_patrol\' => $_POST[\'securityPatrol\'],
    \'maintenance_landscaping\' => $_POST[\'landscaping\'], 
    \'maintenance_building\' => $_POST[\'buildingMaintenance\'],
    \'maintenance_snow_ice\' => $_POST[\'snowIceRemoval\'],
    \'bedrooms_1\' => $_POST[\'1bedroom\'], 
    \'bedrooms_2\' => $_POST[\'2bedroom\'],
    \'bedrooms_3\' => $_POST[\'3bedroom\'],
    \'bedrooms_4\' => $_POST[\'4bedroom\'],
    \'parking_driveway\' => $_POST[\'drivewayParking\'],
    \'parking_car_ports\' => $_POST[\'carPorts\'],
    \'parking_visitor_parking\' => $_POST[\'visitorParking\'],
    \'parking_street_parking\' => $_POST[\'streetParking\'],
    \'parking_garage\'=>$_POST[\'parkingGarage\'],
    \'garages_1space\' => $_POST[\'1space\'], 
    \'garages_2space\' => $_POST[\'2space\'],
    \'garages_3space\' => $_POST[\'3space\'],
    \'garages_no_garages\' => $_POST[\'noGarages\'],
    \'mailbox_indoor_station\' => $_POST[\'indoorMailboxStation\'], 
    \'mailbox_outdoor_station\' => $_POST[\'outdoorMailboxStation\'],
    \'mailbox_personal_mailbox\' => $_POST[\'personalMailbox\'],
    \'amenity_basketball\' => $_POST[\'basketball\'],
    \'amenity_beach_rights\' => $_POST[\'beachrights\'],
    \'amenity_small_craft_boats\' => $_POST[\'smallcraftboats\'],
    \'amenity_boating_slips\' => $_POST[\'boatingslips\'],
    \'amenity_bocce_court\' => $_POST[\'boccecourt\'],
    \'amenity_childrens_pool\' => $_POST[\'childrenspool\'],
    \'amenity_clubhouse\' => $_POST[\'clubhouse\'],
    \'amenity_community_gardens\' => $_POST[\'communitygardens\'],
    \'amenity_day_care\' => $_POST[\'daycare\'],
    \'amenity_elevator\' => $_POST[\'elevator\'],
    \'amenity_fishing\' => $_POST[\'fishing\'],
    \'amenity_golf\' => $_POST[\'golf\'],
    \'amenity_indoor_pool\' => $_POST[\'indoorpool\'],
    \'amenity_outdoor_pool\' => $_POST[\'outdoorpool\'],
    \'amenity_pond\' => $_POST[\'pond\'],
    \'amenity_racquetball\' => $_POST[\'racquetball\'],
    \'amenity_restaurant\' => $_POST[\'restaurant\'],
    \'amenity_skating_rink\' => $_POST[\'skatingrink\'],
    \'amenity_skiing\' => $_POST[\'skiing\'],
    \'amenity_tennis_court\' => $_POST[\'tenniscourt\'],
    \'amenity_volleyball\' => $_POST[\'volleyball\'],
    \'amenity_walking_trails\' => $_POST[\'walkingtrails\'],
    \'amenity_waterfront\' => $_POST[\'waterfront\']



));

}

?>
如果我只做前四次插入,它将正常工作。我还需要一份记录中的所有信息。

有人有什么想法吗?

1 个回复
SO网友:Sean McVey

我的数据库服务器是问题所在。有一些列是HTML格式的,但不在数据库中。对不起,这个愚蠢的问题。

相关推荐

$wpdb->GET_RESULTS()不使用Unicode‘where’子句获取结果

我只需要一个简单的查询,就可以找到一个学生用孟加拉语写的名字记录。 $student_rcrd = $wpdb->get_results(\"SELECT * FROM student WHERE name=\'আবুল কালাম আজাদ\'\"); 虽然我的数据库中有\'আবুল কালাম আজাদ\', 查询返回零行!但与此查询不同,它工作得非常好- $student_rcrd = $wpdb->get_results(\"SELECT * FROM stud