设置TINYINT值失败但MySQL错误不打印任何内容

时间:2016-01-16 19:41:37

标签: php mysql html5

检查以前有关使用TINYINT值的问题,我意识到我面临一个独特的案例因此我的问题。我正在尝试使用复选框将值插入到具有TINYINT字段的表'faculty'中,并同时将值分隔到'admin'表中。该插件适用于'admin'表,但不适用于'faculty',MySQL Error不打印任何内容。MySQL Error prints nothing

PHP脚本---

<?php  
if (isset($_POST['submit'])) {
    $staff_id = $_POST["staff_id"];
    $first_name = $_POST["first_name"];
    $last_name = $_POST["last_name"];
    $preschool = isset($_POST["preschool"]) ? 1 : 0;
    $year1 = isset($_POST["year1"]) ? 1 : 0;
    $year2 = isset($_POST["year2"]) ? 1 : 0;
    $year3 = isset($_POST["year3"]) ? 1 : 0;
    $year4 = isset($_POST["year4"]) ? 1 : 0;
    $year5 = isset($_POST["year5"]) ? 1 : 0;
    $year6 = isset($_POST["year6"]) ? 1 : 0;

    $username = $_POST["username"];
    $password = $_POST["password"];
    $role = "Teacher";

    $sql  = "insert into faculty (staff_id, firstname, lastname, preschool, year1, year2, year3, year4, year5, year6)";
    $sql .= " values ({$staff_id}, '{$first_name}', '{$last_name}', {$preschool}, {$year1}, {$year2}, {$year3}, {$year4}, {$year5}, {$year6})";
    $result = mysqli_query($connection, $sql);

    $sql2  = "insert into admin (staff_id, first_name, last_name, role, username, password)";
    $sql2 .= " values ({$staff_id}, '{$first_name}', '{$last_name}', '{$role}', '{$username}', '{$password}')";
    $result2 = mysqli_query($connection, $sql2);

    //if (!$result) {
        //echo 'MySQL Error: ' . mysqli_error($connection);
        //exit;
    //}

    if ($result && $result2) {
        $_SESSION["message"] = "New faculty added successfully.";
        redirect_to("faculty.php");
    } else {
        $_SESSION["message"] = "Operation failed.";
        redirect_to("new_faculty.php");
    }
}
?>

HTML ---

<div class="checkbox">
    <label>Preschool </label> &nbsp <input type="checkbox" name="preschool">
    <label>Year 1 </label> &nbsp <input type="checkbox" name="year1">
    <label>Year 2 </label> &nbsp <input type="checkbox" name="year2">
    <label>Year 3 </label> &nbsp <input type="checkbox" name="year3">
    <label>Year 4 </label> &nbsp <input type="checkbox" name="year4">
    <label>Year 5 </label> &nbsp <input type="checkbox" name="year5">
    <label>Year 6 </label> &nbsp <input type="checkbox" name="year6">
</div>

我的代码出了什么问题?

0 个答案:

没有答案