Jump to content

Archived

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

wouwouke

insert information in form for datetime variable

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

Share this post


Link to post
Share on other sites
That should work just fine... what code are you using now?

Share this post


Link to post
Share on other sites

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>";
}

?>

Share this post


Link to post
Share on other sites

lol this post was posted in october haha dont think he'd be seeing our replies now.

Share this post


Link to post
Share on other sites

×

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.