KoKsMAN KoKsMAN - 5 months ago 14
SQL Question

MySQL date column in phpmyadmin

I'm building registration form for my teacher's website.
I have created database called "students" with various rows like "name, surname etc."
Now I would like to add a column named "date_submitted" which will automatically insert current date and time to the row when data is submitted.

For example a student submits his data, the data is inserted into the table and mysql automatically fills the date and time when this insertion occured.

I tried @MLBDG answer from this question MySQL date column auto fill with current date but it doesn't work.

This is the way I do it:
enter image description here
Query:

ALTER TABLE `students` ADD `date_submitted` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER ;


The error I'm receiving:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Server version: 5.5.34 - MySQL Community Server (GPL)

Answer

Remove AFTER keyword at the end of your query:

ALTER TABLE `students` ADD `date_submitted` TIMESTAMP on update CURRENT_TIMESTAMP
NOT NULL DEFAULT CURRENT_TIMESTAMP;

Syntax: ALTER TABLE

If using the AFTER keyword in your ALTER TABLE query, it must be followed by the name of a field in the table you are modifying.