duanhongqiong9460 2018-04-29 12:13
浏览 27
已采纳

PHP:无法将某些条目留空

I have created simple PHP form which includes entries of double, date and varchar values. It worked just fine on localhost and the user could input some entries, leaving the others blank. But on server data entry is successful only when all values are entered. In MySQL, the records can take null value but still, there is the following error:

Incorrect double value: '' for column 'birthweight' at row 1
                             or 

Incorrect double value: '' for column 'date' at row 1

My form looks like this:

<tr>
                <td>Birth Weight</td>
                <td><input type="text" name="birthweight"  placeholder=" Enter Birth Weight"> Kg</td>
              </tr>
              <tr>
                <td>Date of Birth</td>
                <td><input type="date" name="DateOfBirth"  name="DateOfBirth" class="Select"></td>
              </tr>
              <tr>
                <td>Sex</td>
                <td><select name="sex"  class="Select">
                        <option value ="--"> Select </option>
                          <option value="Male ">Male</option>
                    <option value="Female">Female</option>
                    </select>
                </td>

php code:

$db = mysqli_real_escape_string($link, $_REQUEST['DateOfBirth']);
$sx = mysqli_real_escape_string($link, $_REQUEST['sex']);
$birthwt = mysqli_real_escape_string($link, $_REQUEST['birthweight']);

$sql = "INSERT INTO tab1 (db, sx, birthwt)
VALUES ('$db', '$sx', '$birthwt')";

This is the table in the database: enter image description here

  • 写回答

1条回答 默认 最新

  • dongya8378 2018-04-29 13:07
    关注

    The database was set to strict mode, changed it to NO_ENGINE_SUBSTITUTION and it worked.

    Command in MySQL:

    SET GLOBAL sql_mode = 'NO_ENGINE_SUBSTITUTION';
    SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION';
    

    and to check whether the changes have been made:

    SELECT @@GLOBAL.sql_mode;
    SELECT @@SESSION.sql_mode;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 YOLOv8obb获取边框坐标时报错AttributeError: 'NoneType' object has no attribute 'xywhr'
  • ¥15 r语言神经网络自变量重要性分析