Jump to content

date function doesnt insert into the database


kleb

Recommended Posts

i have been trying to insert date with when users post there comment but when i echo the date() with the comments..it just display 0000.00.00.00 just like that and when i checked my DB it was like that too..please what can i do.this is my code

Thankd in advance

<?php
include"header.php";
if(isset($_POST['submit']))
{
$postdate=mktime(0,0,0,date("m"),date("d")+1,date("y"));
$comment=mysql_real_escape_string($_POST['comment']);
if($comment!=='')
{
$ins="INSERT INTO post(post_content,post_date)VALUES('$comment','$postdate')";
mysql_query($ins) or die(mysql_error());
}
else
{
echo"You can not post an empty page";
}
}

Link to comment
Share on other sites

Shoot me down if this is an overly simplistic suggestion...but could you not just use 'Time stamp' as one of your mysql  table columns? This would then save you having to do all the date processing to create the date.

 

 

 

i have been trying to insert date with when users post there comment but when i echo the date() with the comments..it just display 0000.00.00.00 just like that and when i checked my DB it was like that too..please what can i do.this is my code

Thankd in advance

<?php
include"header.php";
if(isset($_POST['submit']))
{
$postdate=mktime(0,0,0,date("m"),date("d")+1,date("y"));
$comment=mysql_real_escape_string($_POST['comment']);
if($comment!=='')
{
$ins="INSERT INTO post(post_content,post_date)VALUES('$comment','$postdate')";
mysql_query($ins) or die(mysql_error());
}
else
{
echo"You can not post an empty page";
}
}

Link to comment
Share on other sites

You can do a time stamp just by going into your database on php myadmin. Then add a column to the table and in the drop down for 'type' (that's the dropdown with VARCHAR, INT etc.) there is an option for DATE and TIME.  You can select various variations on the date and time from the drop down. Then everytime a record is added to the database it will automatically add the current date and time to that field. So you don't have to do it.

 

You can then retreive the date and time as you would any other database value.

 

 

 

how do i use the time stamp..do i write it together as in TIMESTAMP?

Link to comment
Share on other sites

If the date and time is being sent to the database (they are not displaying properly) then there is no reason why this should not work:

 

<?php
include"header.php";
if(isset($_POST['submit']))
{
$postdate = date("m/d/y/ H:i");
$comment=mysql_real_escape_string($_POST['comment']);
if($comment!=='')
{
$ins="INSERT INTO post(post_content,post_date)VALUES('$comment','$postdate')";
mysql_query($ins) or die(mysql_error());
}
else
{
echo"You can not post an empty page";
}
}
?>

Link to comment
Share on other sites

hi Mellor God bless you a million times..it worked..wow am so happy now it shows the date instead of the 000.00.00.00 it showed before..but the date is not correct

 

No problem. Is it because I set it to GMT? It is correct for me, but you could change it to what is right for you

Link to comment
Share on other sites

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.