May 6, 2012
insert date data into access database using php?
Question by Illyricum
I am trying to insert data to access database but I am having a problem. I know the problem is when I am inserting value date because i tried to put NULL there and it worked and inserted everything except the date. I also tried to put date in a string ‘date’ to take is as a string but it didnt work. Any idea?
$query_insert = "insert into orders (Ord_Date, Cus_Id_Fk, Book_Id_Fk) Values ($date,$cus_id, $book_id)";
$insert = odbc_exec($conn, $query_insert) or die (odbc_errormsg());
As I said this one with NULL worked, but I need also the date to be inserted.
$query_insert = "insert into orders (Ord_Date, Cus_Id_Fk, Book_Id_Fk) Values (null, $cus_id, $book_id)";
$insert = odbc_exec($conn, $query_insert) or die (odbc_errormsg());
Answer by Starx
Since your date format is MM-DD-YYYY
, you have to prepare the $date to fits that format. Here is how
$date = date("d-m-Y");
$query_insert = 'INSERT INTO .... ';