Jump to content

[SOLVED] inserting date


TGM

Recommended Posts

I want to insert date from page to mysql:

This is what I got but does work

 

<?php

$hostname = "localhost";
$db_user = "root";
$db_password = "";
$database = "users";
$db_table = "orders";

$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db);

$query_auto = "INSERT INTO $db_table (date)
              VALUE ( CURDATE() )";
?>

 

I have a table name orders...in that table I have a date column but it only store "0000-00-00"

Link to comment
https://forums.phpfreaks.com/topic/157566-solved-inserting-date/
Share on other sites

Hi,

how have you got the date column of your table set up, DATETIME ?

try the following, it's a silly way of doing it, but you will be able to figure out whether it is a problem with your php or a problem with the mysql table structure.

 

$mysqldate = date('Y-m-d H:i:s', time());
echo $mysqldate;
$query_auto = "INSERT INTO $db_table ('date') VALUE ( '$mysqldate' )";

good luck!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.