我正在处理其他人的代码,看起来 MySQL Insert 语句存在一些问题......
第 1 行的列“floorSize”的数据被截断
它似乎对很多字段都这样做,但理想情况下我希望它们可以为空。
所以我遍历发布的数据并寻找一个空字符串,如果它是一个空字符串,我想将该变量重置为 NULL。这样数据库就可以接受空值而不是''字符串。
目前,我正在使用 foreach 循环来查看它的值是否为空,然后尝试将该值设置为 NULL。但是没有太多的看点
当前的代码片段是:
function add_user($first_name, $last_name, $gender, $date_of_birth, $address1, $address2, $city, $state, $country, $zip_code, $mobile, $phone, $username, $email, $password, $profile_image, $description, $status, $user_type, $property, $VAN, $agent, $propertyType, $buyerType, $houseName, $street, $postcode, $parish, $zoning, $lat, $lng, $price, $ARV, $tax, $fees, $availableDate, $term, $type, $bedrooms, $bathrooms, $powderrooms, $guestAccom, $furnished, $shortDescription, $floorSize, $plotSize, $pool, $waterfront, $dock, $tennis, $view, $garden, $pets, $fireplace, $laundry, $ac, $patio, $deck, $verandah, $beach, $propertySkipper, $mooring, $gym, $showMap, $display, $videoURL, $garage, $tankSize, $water, $well, $tank, $holiday) {
global $db;
$vars = $_POST;
$count = 0;
foreach($vars as $k => $v)
{
if($v == '')
{
$k = NULL;
}
}
//Running Query to add user.
}
因此,例如 $floorSize 设置为 '' 但理想情况下我想覆盖以将其设置为 NULL。
Smart猫小萌
红颜莎娜