【发布时间】:2016-06-21 02:16:12
【问题描述】:
我是 php 和 oracle 的新手,我正在尝试将表单中的数据插入数据库,但出现以下错误。
警告:oci_execute(): ORA-01400: cannot insert NULL into ("OE"."CUSTOMERS"."CUST_LAST_NAME") in C:\wamp\www\PhpProject1\newentries.php on line 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';
}
【问题讨论】:
-
您正在将空值插入其中一个列:主键、名字、姓氏。可能是主键,您是否设置了触发器来插入它?
-
没有为插入设置触发器。