1

I have read several posts that relate to this question, but I still can not understand what I am doing wrong. For instance:

Saving timestamp in mysql table using php and Display the date of creation of a row in mysql

All I want is to have the date a record is created put in a column of mysql database and then post it to a php results table.

I have added a column to the database called 'Date' with Type:timestamp, Default:current_timestamp(), and Attributes:ON UPDATE CURRENT_TIMESTAMP(). For some reason all rows in the 'Date' column show nothing but zeroes?

How can I set up the column so it actually displays the creation date for each record?

Here is a screenshot of my database structure: enter image description here

And here is a screenshot of the database records:

enter image description here

Any help would be greatly appreciated.

1 Answer 1

0

I figured it out! I was trying to insert the date via my insert.php script and it was finding a null value. Once I removed the insertion of 'Date' it works as expected. Rookie mistake.

Here is what the insert.php looked like prior to my edit:

$sql = "INSERT INTO Medicard (Date, Name, Number, PartA, PartB, Full_Name, Address, Apt, City, State, Zip, Phone, Email) VALUES ('$_POST[Date]','$_POST[Name]','$_POST[Number]','$_POST[parta]','$_POST[partb]','$_POST[Full_Name]','$_POST[Address]','$_POST[Apt]','$_POST[City]','$_POST[State]','$_POST[Zip]','$_POST[Phone]','$_POST[Email]')";

I then removed the 'Date' insertion and it worked:

$sql = "INSERT INTO Medicard (Name, Number, PartA, PartB, Full_Name, Address, Apt, City, State, Zip, Phone, Email) VALUES ('$_POST[Name]','$_POST[Number]','$_POST[parta]','$_POST[partb]','$_POST[Full_Name]','$_POST[Address]','$_POST[Apt]','$_POST[City]','$_POST[State]','$_POST[Zip]','$_POST[Phone]','$_POST[Email]')";
Sign up to request clarification or add additional context in comments.

3 Comments

@Strawberry You are correct. Had I included my insert.php code a more experienced coder may have been able to quickly provide a solution. I will be more diligent in the future.
Incidentally, this approach leaves you exposed to sql injection. See about the importance of prepared and bound queries.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.