未定义的索引:operator_id

时间:2013-10-04 11:13:39

标签: php oracle

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

未定义索引:

中的operator_id

<?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 个答案:

答案 0 :(得分: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 的数据。

答案 1 :(得分:0)

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

问题似乎是

$_POST['operator_id']

使用var_dump()控制接收的数据或将变量置于isset

if(isset($_POST['operator_id']){
//do something
}

答案 2 :(得分:0)

你有意刷新页面吗?刷新页面时会出现什么情况?如果您在刷新页面时不想要任何操作,那么您应该修改if语句。现在如果帖子提交你进入如果......当你没有帖子时你去其他部分...你有一个错误,因为你手上没有帖子数据而你正试图用帖子做点什么数据

答案 3 :(得分: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);
    }       
}


?>