Jump to content

insert information in form for datetime variable


wouwouke

Recommended Posts

As you will read below, I'm a real noob on this... and trying to make some dynamism on my website...

I know how a user can insert data into a field in a form, and then input this information into the database. But for a datetime variable (in mysql), I don't seem to find a way to insert data... I tried using a text field where the user inputs something like '2006-11-01 15:15:15', but this does not seem to work. Could anyone provide me some code to insert dates via a form in a mysql database?

Thanks
  • 4 years later...

yeah i just tested that code on a mysql db and it works for me. can you put a or die(mysql_error()) on your query and see what it says. show us your insert statement. heres my example one i used just for testing not to make code secure and nice etc...

 


<?php

$conn = mysql_connect("***","***","***");
mysql_selectdb("testsql");
$timestampInSeconds = $_SERVER['REQUEST_TIME'];
$mySqlDateTime= date("Y-m-d H:i:s", $timestampInSeconds);

mysql_query("insert into hello (`test1`)values('$mySqlDateTime')");

$q = mysql_query("select * from hello");
while($row = mysql_fetch_array($q,MYSQL_ASSOC)){
  echo $row['test1']."<br>";
}

?>

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.