Jump to content

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

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.