-3

我正在使用此代码使用 php 和数据插入将数据插入到 oracle 数据库中,但在 oracle 数据库中我使用的不是空值。但是当我刷新页面时出现错误:

未定义索引:operator_id in

代码

<?php
{
    $ora_conn = oci_connect('system','oracle','//localhost/XE'); 
    if(!$ora_conn)
    {
        $m = oci_error();
        echo $m['message'], "\n"; 
        exit; 
    } 
    else 
    { 
        //print "You are connected to the database!<br/>"; 
    }
    if (isset($_POST['Submit']))
    {
        $optid = $_POST['operator_id'];
        $optdec = $_POST['operater_description'];
        $empid = $_POST['employee_id'];
        $empmail = $_POST['employee_emailid'];
    }
    $query = "SELECT * FROM optr_add WHERE OPERATOR_ID= 
        '".$_POST['operator_id']."' OR        
        employee_emailid = '".$_POST['employee_emailid']."' 
        OR employee_id =       '".$_POST['employee_id']."'";
    $s=oci_parse($ora_conn, $query);   
    oci_execute ($s,OCI_DEFAULT); 
    $objResult = oci_fetch_array($s); 
    if($objResult) 
    { 
        echo "<script>alert('Operator ID already exist')</script>"; 
    } 
    else
    {
        $query = 'INSERT INTO optr_add 
            (operator_id , operater_description  ,employee_id,employee_emailid)**<<---here**    
            VALUES (:operator_id ,:operater_description,:employee_id,:employee_emailid)';

        $s=oci_parse($ora_conn, $query);
        oci_bind_by_name($s, ':operator_id', $optid );
        oci_bind_by_name($s, ':operater_description', $optdec); 
        oci_bind_by_name($s, ':employee_id', $empid);
        oci_bind_by_name($s, 'employee_emailid', $empmail );
        if (isset($_POST['Submit']))
            $objExecute=oci_execute($s);
        if (isset($_POST['Submit']))
        {
            if (!isset($optid) || empty($optid)) 
            {
                //header( "refresh:1110;url=Define_Organization.php" );
                echo"<script>alert('Submit Successfully')</script>"; 
                exit();
                echo"<script>alert('Please enter your data')</script>"; 
                exit();
            }
        }
        oci_free_statement($s);
        oci_close($ora_conn);
    }
}
?>
4

4 回答 4

0

您确定您在此页面上通过 POST 收到“operator_id”字段吗?

问题似乎是

$_POST['operator_id']

使用 var_dump() 控制收到的数据或将变量放在 isset 中

if(isset($_POST['operator_id']){
//do something
}
于 2013-10-04T11:18:31.957 回答
0

使用以下代码:

$optid = isset($_POST['operator_id']) ? $_POST['operator_id'] : '';
$optdec = isset($_POST['operater_description']) ? $_POST['operater_description'] : '';
$empid = isset($_POST['employee_id']) ? $_POST['employee_id'] :'';
$empmail = isset($_POST['employee_emailid']) ? $_POST['employee_emailid'] : '';

可能是您没有从表单中发布operator_id的数据。

于 2013-10-04T11:15:53.433 回答
0

使用更新的代码并尝试一下:

<?php
$ora_conn = oci_connect('system','oracle','//localhost/XE'); 
if(!$ora_conn)
{
    $m = oci_error();
    echo $m['message'], "\n"; 
    exit; 
} 
else 
{ 
    //print "You are connected to the database!<br/>"; 
}
if (isset($_POST['Submit']))
{
    $optid = $_POST['operator_id'];
    $optdec = $_POST['operater_description'];
    $empid = $_POST['employee_id'];
    $empmail = $_POST['employee_emailid'];
    $query = "SELECT * FROM optr_add WHERE OPERATOR_ID= 
        '".$_POST['operator_id']."' OR        
        employee_emailid = '".$_POST['employee_emailid']."' 
        OR employee_id =       '".$_POST['employee_id']."'";
    $s=oci_parse($ora_conn, $query);   
    oci_execute ($s,OCI_DEFAULT); 
    $objResult = oci_fetch_array($s); 
    if($objResult) 
    { 
        echo "<script>alert('Operator ID already exist')</script>"; 
    } 
    else
    {
        $query = 'INSERT INTO optr_add 
            (operator_id , operater_description  ,employee_id,employee_emailid)**<<---here**    
            VALUES (:operator_id ,:operater_description,:employee_id,:employee_emailid)';

        $s=oci_parse($ora_conn, $query);
        oci_bind_by_name($s, ':operator_id', $optid );
        oci_bind_by_name($s, ':operater_description', $optdec); 
        oci_bind_by_name($s, ':employee_id', $empid);
        oci_bind_by_name($s, 'employee_emailid', $empmail );
        if (isset($_POST['Submit']))
            $objExecute=oci_execute($s);
        if (isset($_POST['Submit']))
        {
            if (!isset($optid) || empty($optid)) 
            {
                //header( "refresh:1110;url=Define_Organization.php" );
                echo"<script>alert('Submit Successfully')</script>"; 
                exit();
                echo"<script>alert('Please enter your data')</script>"; 
                exit();
            }
        }
        oci_free_statement($s);
        oci_close($ora_conn);
    }       
}


?>
于 2013-10-04T11:26:34.673 回答
0

您是否有意刷新页面?刷新页面时会是什么?如果您在刷新页面时不想要任何操作,那么您应该修改您的 if 语句。现在,如果提交了帖子,您将进入 if...当您没有帖子时,您会转到 else 部分...您有一个错误,因为您手中没有帖子数据并且您正在尝试对 post 做一些事情数据。

于 2013-10-04T11:19:08.157 回答