0

I am using the code below to insert time into a table, and this is the output it's giving me: 0000-00-00

//table
start DATETIME,

//code to insert date into db
$_POST['start']=date("Y-m-d H:i:s");
$insert = "INSERT INTO eguardIPs (Field1,Field2,Field3,start)
VALUES ('".$_POST['Field1']."', '".$_POST['Field2']."', '".$_POST['Field3']."', '".$_POST['start']."')";
$add_start = mysql_query($insert);
3
Contributors
9
Replies
10
Views
7 Years
Discussion Span
Last Post by Brianbc
0

If you want to insert the current timestamp you can use NOW(), like this;

$insert = "INSERT INTO eguardIPs (Field1,Field2,Field3,start)
VALUES ('".$_POST['Field1']."', '".$_POST['Field2']."', '".$_POST['Field3']."', NOW())";
0

Very well, this does work and I can make do with it for now, though I would hsve liked to save something like this (2010-11-06 15:38:28) in the table, && ! this (2010-11-06). My field is DATETIME.

$insert = "INSERT INTO eguardIPs (Field1,Field2,Field3,start)
 VALUES ('".$_POST['Field1']."', '".$_POST['Field2']."', '".$_POST['Field3']."', NOW())";
0

Try this.

$date = date("Y-m-d H:i:s"); 
INSERT INTO equardIPs (start) VALUES(" . $date . ")
0

fobos, that's more or less where I started from, only this time the field is blank!

0

Nothing above seems to work, so I've crafted an ingenious way around it.

When you insert a new record, this does not work

$insert = "INSERT INTO eguardIPs (Field1,Field2,Field3,start)
   
      VALUES ('".$_POST['Field1']."', '".$_POST['Field2']."', '".$_POST['Field3']."', NOW())";

But when you are updating an existing record, it does work

$query = "UPDATE eguardIPs SET start=(now()) WHERE id='".$_POST['id']."'";
	$add_start = mysql_query($query);

So I've decided to first enter data for the other fields, then UPDATE the date field.

$insert = "INSERT INTO eguardIPs (Field1,Field2,Field3)
VALUES ('".$_POST['Field1']."', '".$_POST['Field2']."', '".$_POST['Field3']."')";
$add_member = mysql_query($insert);
						
$check=mysql_query("SELECT * FROM eguardIPs WHERE user!='IloveBibiana'");
						
$_POST['id']=((mysql_num_rows($check))+1);
setcookie(id, $_POST['id']);
						
$_POST['id']=$_COOKIE['id']; 
$query = "UPDATE eguardIPs SET start=(now()) WHERE id='".$_POST['id']."'";
$add_start = mysql_query($query);

A more straightfoward way is still welcome.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.