user2308205
user2308205

Reputation: 39

Trying to insert Date into Oracle Database via php but Code isint working

im creating a project and im having problems inserting the date into the oracle database , i am using data binding ,everything else works but date isint getting inserted ..

$bkida = @$_POST['bkida'];
$titlea = @$_POST['titlea'];
$athr = @$_POST['athr'];
$pblr = @$_POST['pblr'];
$edtn = @$_POST['edtn'];
$btype = @$_POST['btype'];
$pdatea = @$_POST['pdatea'];
$indatea = @$_POST['indatea'];
$tbooks = @$_POST['tbooks'];
$tpages = @$_POST['tpages'];

$cmts = @$_POST['cmts'];

$sql = "INSERT INTO books(ISBN,   TITLE, AUTHOR,PUBLISHER,EDITION,BK_TYPE,PRINT_DT,   IN_DT,     TOT_BKS,  AVAIL_BKS,  PAGES,  COMMENTS) 
"."VALUES(:bkida,:titlea,:athr,:pblr,     :edtn,  :btype  ,to_date(:pdatea, 'MM-DD-YYYY'), to_date(:indatea, 'MM-DD-YYYY'),  :tbooks ,  :tbooks,  :tpages ,  :cmts   )";

$compiled = oci_parse($conn, $sql);

oci_bind_by_name($compiled, ':bkida', $bkida);
oci_bind_by_name($compiled, ':titlea', $titlea);
oci_bind_by_name($compiled, ':athr', $athr);
oci_bind_by_name($compiled, ':pblr', $pblr);
oci_bind_by_name($compiled, ':edtn', $edtn);
oci_bind_by_name($compiled, ':btype', $btype);

oci_bind_by_name($compiled, ':pdatea', $pdatea);
oci_bind_by_name($compiled, ':indatea', $indatea);
oci_bind_by_name($compiled, ':tbooks', $tbooks);
oci_bind_by_name($compiled, ':tpages', $tpages);
oci_bind_by_name($compiled, ':cmts', $cmts);


oci_execute($compiled);

Upvotes: 0

Views: 1350

Answers (2)

user2308205
user2308205

Reputation: 39

Solved , after i used echo i gt a weird output , so i played with the values of y-m-d and finally got this code to work

$pdatea = date("m-d-Y",strtotime(@$_POST['pdatea']));
indatea = date("m-d-Y",strtotime(@$_POST['indatea'])); 

Thanks Mr Niranjan for the help :D

Upvotes: 1

Niranjan N Raju
Niranjan N Raju

Reputation: 11987

The default date format will be YYYY-MM-DD, I think you are trying to insert in some other format. Convert your date like this before inserting to database

$pdatea = date("Y-m-d",strtotime(@$_POST['pdatea']));
$indatea = date("Y-m-d",strtotime(@$_POST['indatea']));

Upvotes: 1

Related Questions