我已经创建了一个客户端地址簿,但是似乎不能添加新的客户端


I have created a client address book, but can't seem to add new clients

我已经为我的客户端应用程序创建了一个地址簿。我可以登录和退出。当我点击刷新,重定向重新登录时,浏览器不会记住数据,所有这些都很好,但是添加下面的文件后要添加新的客户端。我不能这样做。有人可以帮助我确定为什么我不能成功添加新客户吗?

<?php
session_start();
// if user is not logged in
if(!$_SESSION['loggedInUser']) {
    // send them to the login page
    header("Location: index.php");
}
// connect to the database
include('includes/connection.php');
// include functions file
include('includes/functions.php');
// if add button was submitted
if(isset($_POST['add'])) {
    // set all variables to empty by default
    $clientName = $clientEmail = $clientPhone = $clientAddress =$clientCompany = $clientNotes = "";
    // check to see if inputs are empty
    // create variables with form data
    // wrap the data with our function
    if($_POST["clientName"]) {
        $nameError = "Please enter a name <br>";
    } else {
        $clientName = validateFormData($_POST["clientName"]);
    }
    if($_POST["clientEmail"]) {
        $emailError = "Please enter a email <br>";
    } else {
        $clientEmail = validateFormData($_POST["clientEmail"]);
    }
    // these inputs are not required
    // so we'll just store whatever has been entered
    $clientPhone    = validateFormData($_POST["clientPhone"]);
    $clientAddress    = validateFormData($_POST["clientAddress"]);
    $clientCompany    = validateFormData($_POST["clientCompany"]);
    $clientNotes    = validateFormData($_POST["clientNotes"]);
    // if required fields have data
    if($clientName && $clientEmail) {
        // create query
        $query = "INSERT INTO client(id, name, email, phone, address, company, notes, date_added) VALUES(NULL, '$clientName', '$clientEmail', '$clientPhone', '$clientAddress', 'clientCompany', 'clientNotes', CURRENT_TIMESTAMP)";
        $result = mysqli_query($conn, $query);
        // if query was successful
        if($result) {
            // refresh page with query string
            header("Location: clients.php?alert=success");
        } else {
            // something went wrong
            echo "Error: ".$query."<br>".mysqli_error($conn);
        }
    }
}
// close the mysql connection
mysqli_close($conn);

include('includes/header.php');
?>
<h1>Add Client</h1>
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post" class="row">
    <div class="form-group col-sm-6">
        <label for="client-name">Name *</label>
        <input type="text" class="form-control input-lg" id="client-name" name="clientName" value="">
    </div>
    <div class="form-group col-sm-6">
        <label for="client-name">Email *</label>
        <input type="text" class="form-control input-lg" id="client-email" name="clientEmail" value="">
    </div>
    <div class="form-group col-sm-6">
        <label for="client-phone">Phone</label>
        <input type="text"
 class="form-control input-lg" id="client-phone" name="clientPhone" value="">
    </div>
    <div class="form-group col-sm-6">
        <label for="client-address">Address</label>
        <input type="text" class="form-control input-lg" id="client-address" name="clientAddress" value="">
    </div>
    <div class="form-group col-sm-6">
        <label for="client-company">Company</label>
        <input type="text" class="form-control input-lg" id="client-company" name="clientCompany" value="">
    </div>
    <div class="form-group col-sm-6">
        <label for="client-notes">Notes</label>
        <textarea type="text" class="form-control input-lg" id="client-notes" name="clientNotes"></textarea>
    </div>
    <div class="col-sm-12">
        <a href="clients.php" type="button" class="btn btn-lg btn-default">Cancel</a>
        <button type="submit" class="btn btn-lg btn-success pull-right" name="add">Add Client</button>
    </div>
</form>
<?php
include('includes/footer.php');
?>

检查您的"client"表是否允许ID值为NULL。我认为这就是问题所在因为如果你正确设置了你的表这将是你的主键不应该是NULL