Jump to content


Photo

insert information in form for datetime variable


  • Please log in to reply
3 replies to this topic

#1 wouwouke

wouwouke
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 30 October 2006 - 12:42 PM

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

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 30 October 2006 - 05:16 PM

That should work just fine... what code are you using now?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 jake2891

jake2891
  • Members
  • PipPipPip
  • Advanced Member
  • 113 posts

Posted 06 January 2011 - 06:30 AM

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

?>


#4 jake2891

jake2891
  • Members
  • PipPipPip
  • Advanced Member
  • 113 posts

Posted 06 January 2011 - 06:36 AM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users