PHP:无法将某些条目留空

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

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;