警告:oci_execute():ORA-01400:无法插入NULL值

时间:2016-03-07 13:39:22

标签: php oracle

我是php&的新手。 oracle和我试图将数据从表单插入数据库但发生错误。

  

警告:oci_execute():ORA-01400:无法在C:\ wamp中插入NULL(" OE"。" CUSTOMERS"。" CUST_LAST_NAME")第39行\ www \ PhpProject1 \ newentries.php

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

<?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

1 个答案:

答案 0 :(得分:1)

您的代码中有一个简单的拼写错误:

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