0

i am trying to run this php code to insert values in oracle database but error showing when run it. my code is:

<?php 
$c = oci_connect('system', 'passward', 'dbname');
$sql = "INSERT INTO EMPLOYEES(EMP_ID,JOB_ID) VALUES (:emp_id, ".'{$nw}'.")";
$compiled = oci_parse($c, $sql);
oci_bind_by_name($compiled, ':emp_id', $eid);
oci_bind_by_name($compiled, '.$nw.', $nw);
oci_execute($compiled);
?>

and i get the folloing errors

Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\folder\add_emp.php on line 16

Warning: oci_execute(): ORA-00911: invalid character in C:\xampp\htdocs\folder\add_emp.php on line 17

Ι know the problem is where Ι write $nw, but just don't know the right syntax or way.

2 Answers 2

1

Try

$sql = "INSERT INTO EMPLOYEES(EMP_ID,JOB_ID) VALUES (:emp_id, :nw)";

the problem in your query is that you're closing the " then concatenating {$nw} exactly this string as you've put it between single quotes, php understands that it shouldn't replace this by a variable it is just a string. so your query is arriving to oracle like this:

INSERT INTO EMPLOYEES (EMP_ID,JOB_ID) VALUES (whatever_int_in_eid, {$nw});

Sign up to request clarification or add additional context in comments.

Comments

0

You doing it incorrectly,

$sql = "INSERT INTO EMPLOYEES(EMP_ID,JOB_ID) VALUES (:emp_id, :nw)";
$compiled = oci_parse($c, $sql);
oci_bind_by_name($compiled, ':emp_id', $eid);
oci_bind_by_name($compiled, ':nw', $nw);

3 Comments

Thank you very mush Rikesh,,, i did it and it worked.
Glad to help you kindly accept it if it helps you in solving your problem.
i did it, tick marj is now green, is this what you was trying to convey??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.