I'd like to add a timestamp to articles I upload to my website, which reads the time and date the article was uploaded. I've got a database, as well as a working connect.php. In this database, I've created a table with a "date" field (type: date). What can I do to get the timestamps working?

I'm confused by your question. The date column would be a column of your articles table, as would the message body column. For example, the following might be a structure of your articles table:

id | title | body | date
------------------------

Your php code would then populate all four columns at once.

Member Avatar for diafol

WHat do you mean by timestamp? Datetime, e.g. 2012-06-24 13:09:34 or UNIX timestamp, e.g. 1340566711 . If you're saving as 'date', you're only saving '2012-06-24'?

By timestamp, I mean a line of text at the top of an article, reading "posted on Y/M/D". As for the confusion, I'm a bit confused myself. I know that databases are supposed to work with rows and columns, but PHPMyAdmin just lets me create a table with fields. So I created a table with a single field, which I named "date".

Member Avatar for diafol

Ok, you probably need to take a deep breath and read up on MySQL, and possibly the phpMyAdmin application. I must be honest - I hate phpMyAdmin, so I use other GUIs. One you may find useful is SQLyog (Community Version), available from here:

http://code.google.com/p/sqlyog/downloads/detail?name=SQLyog-10.1.1-0Community.exe&can=2&q=

That will allow you to add/update/delete easily.

Also, try not to use reserved words (like 'date') for fieldnames. You can do so of course, but you MUST enclose them in `backticks`, otherwise you'll get MySQL errors. It's good practice to enclose all tables and fields in backticks anyway.

Alright, will do. Thanks.

phpMyAdmin fields are the equivalent of table columns. So if you ARE using phpMyAdmin, you'd want to create one table with multiple fields ... title, body, and date.

I actually just got that (inputed an SQL command to create a new column, thereby creating a field).

Member Avatar for diafol

inputed an SQL command to create a new column, thereby creating a field

That's a bit hardcore! :)

How so? MyAdmin has a command input (or command line) option. I just typed ALTER TABLE news ADD postdate VARCHAR(1000);

Member Avatar for diafol

Hit the 'structure' tab on a table and then you can add fields via the interface.

BTW - take care which MySQL version you have, before 5.0.3 varchar will have max length 0-255

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.