Reputation: 279
I have the following code:
function dbInsert()
{
global $dbcon, $dbtable;
global $inputData;
$sqlQuery = 'INSERT INTO ' . $dbtable . ' (id_author, date, title, description) VALUES (?, ?, ?, ?)';
$stmt = $dbcon->prepare($sqlQuery);
echo $sqlQuery;
$stmt->bind_param('isss', $inputData['idAuthor'], $inputData['date'], $inputData['title'], $inputData['description']);
$stmt->execute();
$stmt->close();
header('Location: ./news.php?order=' . $_GET['order'] . '&sort=' . $_GET['sort'] . '&filter=' . $_GET['filter'] . '&page=' . $_GET['page'] . '');
}
$inputData['date'] is formatted as dd.mm.yyyy ex (18.02.2010)
I couldnt find a date parameter so I am trying to insert it as a string, is this right? I assume I need to tell mysql how to handle the input but could not find anything on the subject. The equivalent in ORACLE would be TO_DATE(?, 'dd.mm.yyyy') if it helps clarify what i am asking.
Upvotes: 2
Views: 6015
Reputation: 838696
You could take a look at the STR_TO_DATE function. It takes a format parameter. The allowed values for the format parameter are described here.
$sqlQuery = 'INSERT INTO ' . $dbtable . ' (id_author, date, title, description)' .
' VALUES (?, STR_TO_DATE(?, \'%d.%m.%Y\'), ?, ?)';
Upvotes: 2
Reputation: 508
You can use a date/time column
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-types.html
and use the STR_TO_DATE function:
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_str-to-date
Or you can convert it to a unix timestamp and insert this one in an INT Column.
Upvotes: 1