PHP date and time function wont store in the database
the date in the Database has a field of time which you can insert a date and a time but why is it that it is not being stored all I get is 0's when I check the database, but the other datas are being stored
here's my code
<?php
session_start();
include("Connection.php");
if (isset($_POST['su开发者_开发百科bmit']))
$name = $_POST['customerName'];
$mysqldate = date( 'Y-m-d H:i:s' );
$phpdate = strtotime( $mysqldate );
mysql_query("INSERT INTO `starbucks`.`orders` (
`ID` ,
`NAME` ,
`TOTAL_PRICE` ,
`TOTAL_ITEMS` ,
`TIME`
)
VALUES (
'' , '$name', '', '','$phpdate')") or die(mysql_error());
$_SESSION['user'] = $name;
?>
DATETIME field is a date field, not a timestamp field.
The format is date('Y-m-d H:i:s').
use your $mysqldate instead of $phpdate
mysql_query("INSERT INTO starbucks.orders (
ID ,
NAME ,
TOTAL_PRICE ,
TOTAL_ITEMS ,
TIME
)
VALUES (
'' , '$name', '', '','$mysqldate')") or die(mysql_error());
if you are simply trying to add the current time, you don't need to create a timestamp in php but you can use NOW() in mysql instead
mysql_query("INSERT INTO `starbucks`.`orders` (
`ID` ,
`NAME` ,
`TOTAL_PRICE` ,
`TOTAL_ITEMS` ,
`TIME`
)
VALUES (
'' , '$name', '', '',NOW())")
加载中,请稍侯......
精彩评论