-3

i am using this code for insert the data into oracle database using php and data insert but in oracle database i am using not null values .but when i am refresh the page then getting error:

Undefined index: operator_id in

code

<?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);
    }
}
?>
david
  • 3,225
  • 9
  • 30
  • 43
user2842666
  • 5
  • 1
  • 5
  • 1
    This gets asked pretty often. It has nothing to do with Oracle. Have a look at [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Álvaro González Oct 04 '13 at 11:15

4 Answers4

0

Use the below code:

$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'] : '';

May be you are not post the data of the operator_id from the form.

Code Lღver
  • 15,573
  • 16
  • 56
  • 75
  • thanks but i have getting error on this line Notice: Undefined index: operator_id in $query = "SELECT * FROM optr_add WHERE OPERATOR_ID= '".$_POST['operator_id']."' – user2842666 Oct 04 '13 at 11:30
0

Are you sure that you receive the field "operator_id" by POST on this page ?

The problem seems to be the

$_POST['operator_id']

Control your received data with a var_dump() or place your variable in a isset

if(isset($_POST['operator_id']){
//do something
}
ylerjen
  • 4,109
  • 2
  • 25
  • 43
0

Do you intentionally refresh the page ? What would it be when you refresh the page ? If you do not want any action when refreshing the page then you should revise your if statement. Right now if post submitted you go into if...when you have no post you go to else section...There you have an error because you do not have a post data in your hand and you are trying to do something with post data.

Serhat Akay
  • 536
  • 3
  • 10
0

Use the updated code and make a try:

<?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);
    }       
}


?>
Nes
  • 304
  • 1
  • 10
  • i have getting new error when i submit the add button with null values oci_execute(): ORA-01400: cannot insert NULL into ("SYSTEM"."OPTR_ADD"."OPERATOR_ID") – user2842666 Oct 04 '13 at 11:41
  • but this coding section is not working echo""; exit(); – user2842666 Oct 04 '13 at 11:42
  • Seems you missing some of input. Better before execute oci_execute() try to print_r($_POST) or individually echo $_POST['operator'] and etc. Then try execute the oci_execute() – Nes Oct 04 '13 at 11:44
  • Check whether all inputs are not empty – Nes Oct 04 '13 at 11:45
  • plz explain i am new in php coding – user2842666 Oct 04 '13 at 11:51
  • Copy and paste the above code and tell me you can able to see all the input after submit the form. – Nes Oct 04 '13 at 11:54
  • when i submit the button then print these values on same page opt id: opt description: employee id: employee emailid: pwd: langcd: multl: lpwd: accl: optt: optrals: lsing: lupdt: lupid: – user2842666 Oct 04 '13 at 12:19
  • Use the updated code and check still the error exist... – Nes Oct 04 '13 at 12:26
  • i have getting new error when i submit the add button with null values oci_execute(): ORA-01400: cannot insert NULL into ("SYSTEM"."OPTR_ADD"."OPERATOR_ID") – user2842666 Oct 05 '13 at 06:02
  • Missing colon in this line please check oci_bind_by_name($s, ':employee_emailid', $empmail ); – Nes Oct 05 '13 at 07:01