一般错误:1366不正确的整数值:INT类型的列为“ NULL”

时间:2018-12-22 20:47:29

标签: php html mysql

我的数据库中有一个int列,我根据html \ php代码中下拉菜单的用户选择对其进行更新:

<select name="regularClass">
  <option value=NULL selected>None</option>
<?php
$sql = "SELECT idClass FROM Class WHERE category='ET'";
$result = $conn->query($sql);
$result = $conn->query($sql);
$row_count = $result->rowCount();
if ($row_count > 0){
while ($row = $result->fetch())
  {
    echo "<option value=".$row['idClass'].">".$row['idClass']."</option>";
  }
}
?>
</select><br><br>
Transportaion:
<input type="radio" name="transportation" value="BUS" checked>Bus</option><br>
<input type="radio" name="transportation" value="KHAS">Khas</option><br>
Bus:
<select id="busDropdown" name="bus">
    <option value=NULL selected>None</option>
    <?php
    $sql = "SELECT busNumber FROM Bus";
    $result = $conn->query($sql);
    $row_count = $result->rowCount();
    if ($row_count > 0){
    while ($row = $result->fetch())
      {
        echo "<option value=".$row['busNumber'].">".$row['busNumber']."</option>";
      }
    }
    ?>
    </select><br><br>

在我需要用户选择总线号的地方,如果没有,请选择“无”。我收到错误的问题:

  

致命错误:未捕获的PDOException:SQLSTATE [HY000]:常规错误:1366不正确的整数值:第1行的“ Bus_busNumber”列为

该错误是由以下几行引发的:

<?php
if (isset($_POST['save']))
  {

  try{
  $ssn = $_POST['ssn'];
  } catch (DataIntegrityViolationException $e) {
        System.out.println("Student already registered");
    }
  $fullName = $_POST['fullName'];
  $transportation = $_POST['transportation'];
  $qualification = $_POST['qualification'];
  $neighborhood = $_POST['neighborhood'];
  $dob = $_POST['dob'];
  $email = $_POST['email'];
  $bus = $_POST['bus'] ;
  $grade = $_POST['grade'];
  $notes = $_POST['notes'];
  $nationality = $_POST['nationality'];
  $regularClass = (int)$_POST['regularClass'];
  $mobileNumber = $_POST['mobile'];
  $phone = $_POST['phone'];

  $stmt= $conn->prepare("INSERT INTO Student (ssn, name, transportation, qualification, neighborhood, dob, email, Bus_busNumber, grade,note, nationality, Class_idClass, mobile, phone)
    VALUES (:ssn,:fullName,:transportation,:qualification,:neighborhood,:dob,:email,:bus,:grade,:notes,:nationality,:regularClass,:mobileNumber,:phone)
                                ");
  $stmt->bindParam(':ssn',$ssn);
  $stmt->bindParam(':fullName',$fullName);
  $stmt->bindParam(':transportation',$transportation);
  $stmt->bindParam(':qualification',$qualification);
  $stmt->bindParam(':neighborhood',$neighborhood);
  $stmt->bindParam(':dob',$dob);
  $stmt->bindParam(':email',$email);
  $stmt->bindParam(':bus',$bus);
  $stmt->bindParam(':grade',$grade);
  $stmt->bindParam(':notes',$notes);
  $stmt->bindParam(':nationality',$nationality);
  $stmt->bindParam(':regularClass',$regularClass);
  $stmt->bindParam(':mobileNumber',$mobileNumber);
  $stmt->bindParam(':phone',$phone);
  $stmt->execute();
  $stmt->CloseCursor();
  exit;
}
?>

我知道此错误来自空值,该值是此列的默认值! 我不想更改严格模式(阅读许多文章后找到的解决方案),我需要解决此问题。 请帮我解决这个问题。

0 个答案:

没有答案