警告:oci_execute():ORA-01400:不能插入NULL值

问题描述:

我是新来php &甲骨文,我试图从表单插入数据到数据库中,但出现以下错误。警告:oci_execute():ORA-01400:不能插入NULL值

警告:oci_execute():ORA-01400:不能插入NULL插入(" OE " "客户" " CUST_LAST_NAME "。)在C:\瓦帕\ WWW \ PhpProject1 \ newentries.php第39行上

帮我解释如何将数据插入数据库。 代码是:

<?php 

require_once('./dbinfo.inc.php'); 

session_start(); 


echo <<<EOD 
    <body style="font-family: Arial, sans-serif;"> 

    <form action="newentries.php" method="POST"> 

    <p>First Name: <input type="text" name="firstname"></p> 

    <p>Last Name:<input type="text" name="lastname"</p> 

    <p>CustomerId: <input type = "text" name = "cust_id"></p> 

    <p>Email ID: <input type = "text" name = "cust_email"></p> 

    <input type="submit" value="Submit"> 
    </form> 

    </body> 

EOD; 

if(!empty($_POST['firstname']) && !empty($_POST['lastname']) && !empty($_POST['cust_id']) && !empty($_POST['cust_email'])) 
{ 
    $c = oci_pconnect(ORA_CON_UN, ORA_CON_PW, ORA_CON_DB); 

    $fname = $_POST['firstname']; 

    $lname = $_POST['lastname']; 

$id = $_POST['cust_id']; 

    $email = $_POST['cust_email']; 

    $stid = oci_parse($c, "INSERT INTO CUSTOMERS(CUSTOMER_ID,CUST_FIRST_NAME,CUST_LAST_NAME,CUST_EMAIL) VALUES(:id_bv,:fname_bv,:lname_bv,:email_bv)"); 

    oci_bind_by_name($stid, ':fname_bv', $fname); 

    oci_bind_by_name($stid, ':lname_bv', $lname); 

    oci_bind_by_name($stid, ':id_bv', $id); 

    oci_bind_by_name($stid, ':email_bv', $email); 

    oci_execute($stid); 
} 
else 
{ 
    echo 'error'; 
} 

table in which I want to enter the data

+0

要插入一个空值到其中一列:主键,姓,名称。可能是主键,你是否设置了一个触发器来插入它? – kevinsky

+0

没有设置插入触发器。 – luffy

你在你的代码中简单的拼写错误:

$flname = $_POST['lastname']; 
... 
oci_bind_by_name($stid, ':lname_bv', $lname); 
+0

@vaibhav这不足以让我帮忙。现在您已经编辑了您的问题以删除错字,但请说错误已修复。所以现在你的问题是错误的... – timclutton

+0

@vaibhav检查'oci_execute'的返回值;它应该是“真实的”,以表明声明奏效。如果不是,请调用['oci_error($ c)'](http://php.net/manual/en/function.oci-error.php)以查明哪里出了问题。 – timclutton

+0

该错误意味着记录已经存在。尝试插入不同的值。一个简单的互联网搜索会告诉你这一点。这是我在这里帮助你的第三个不同的问题,因此SO不是支持论坛。我建议你在Web应用程序开发中找到一个教程或者上一堂课。 – timclutton