douyunjiaok300404 2019-05-04 01:56
浏览 62

列'custID'不能为null

I'm trying to use this php document to use a form to input information into a database. I keep getting the same error, Column 'custID' cannot be null. I don't know whats wrong or what to do. I might have to take the L for this assignment but it would be helpful if I could get an answer in case I run into the same problem in the future.

I already tried doing NOT NULL AUTO_INCREMENT in the mysql code. i also tried doing the same thing by using NULL for custID. Neither worked.

if(isset($_POST['submit'])){
        $data_missing = array();            

        if(empty($_POST['custID'])){
            $data_missing[] = 'Customer ID';
            }else{
                $custID = trim($_POST['custID']);
            }
        if(empty($_POST['custFirstName'])){
            $data_missing[] = 'First Name';
            }else{
                $custFirstName = trim($_POST['custFirstName']);
            }
        if(empty($_POST['custLastName'])){
            $data_missing[] = 'Last Name';
            }else{
                $custLastName = trim($_POST['custLastName']);
            }
        if(empty($_POST['address'])){
            $data_missing[] = 'Address';
            }else{
                $address = trim($_POST['address']);
            }
        if(empty($_POST['city'])){
            $data_missing[] = 'city';
            }else{
                $city = trim($_POST['city']);
            }
        if(empty($_POST['custstate'])){
            $data_missing[] = 'State';
            }else{
                $custstate = trim($_POST['custstate']);
            }
        if(empty($_POST['custEmail'])){
            $data_missing[] = 'Email';
            }else{
                $custEmail = trim($_POST['custEmail']);
            }
        if(empty($_POST['custPhone'])){
            $data_missing[] = 'Phone';
            }else{
                $custPhone = trim($_POST['custPhone']);
            }
        if(empty($_POST['Password'])){
            $data_missing[] = 'Password';
            }else{
                $Password = trim($_POST['Password']);
            }
    }

    if(empty($data_missing)){
        require_once '../LabYourLastProject/mysqli_connect.php';
        $query =  "INSERT INTO Customers (custID, custFirstName, custLastName, address, city,"
                . " custstate, custEmail, custPhone, Password) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?)";

        $stmt = mysqli_prepare($dbc, $query);

        mysqli_stmt_bind_param($stmt, "sssssssss", $custID, $custFirstName,$custLastName, $address, $city, $custstate, $custEmail, $custPhone, $Password);

        mysqli_stmt_execute($stmt);

        $affected_rows = mysqli_stmt_affected_rows($stmt);

        if($affected_rows == 1){
            echo 'Student Entered';
            mysqli_stmt_close($stmt);
            mysqli_close($dbc);
        }else{
            echo 'Error Occurred <br />';
            echo mysqli_error($dbc);
        }
    }else{
            echo'You need to enter the following data<br />';
            foreach($data_missing as $missing){
                echo "$missing<br />";
            }
        }

Its supposed to insert the data passed from the form in another file into a database and show what data is missing. I just get the error.

  • 写回答

2条回答 默认 最新

  • douteng5673 2019-05-04 02:10
    关注

    You have to remove custID because is an AUTO_INCREMENT

     $query =  "INSERT INTO Customers (custFirstName, custLastName, address, city,"
                    . " custstate, custEmail, custPhone, Password) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
    

    and this code

        mysqli_stmt_bind_param($stmt, "sssssssss", $custFirstName,$custLastName, $address, $city, $custstate, $custEmail, $custPhone, $Password);
    
    评论

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装