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 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊