PHP works natively with the MySQL database, so these two languages are used in blogs, social networking sites and personal websites. When you create a MySQL database record, inserting the date and time stamp lets you keep track of when the record was created. You use the "date" function in PHP to retrieve the date, then insert it with other record information into your MySQL table.
Right-click the PHP file you want to use to insert the record. Select "Open With," then double-click the PHP editor in the list of programs.
Scroll down to the section of your code that contains the PHP code. All PHP code is contained within the opening "<?php" and closing "?>" tags.
Create a variable that contains the date. The "date" function in PHP lets you set up a date with any format. The format you use does not matter, because the MySQL database engine always saves the date with the default syntax. Type the following code to create a date variable:
$date = date();
Create the database connection. Before you insert records into MySQL, you must set up a database connection. The following code creates a connection:
$connection = mysql_connect("localhost","username","password");
Replace "username" and "password" with your own MySQL database user name and password. Replace "database_name" with the name of the database on your server.
Create the "insert" query. For example, if you want to insert a new customer record, the following code creates a new record with the customer name "Joe Smith" and uses the data variable to insert the date into the table:
mysql_query("insert into customer (FirstName, LastName, CreateDate)
values ('Joe', 'Smith', $date')");
How to Insert a Range of Numbers Into an SQL Table
SQL Server is a Relational Database Management System designed by Microsoft for Enterprise database solutions. In the Enterprise network there can be...
How to Insert a Date Stamp With Dreamweaver
A date stamp lets users know when you've updated a Web page. It's a great feature if you update regularly, but it...
How to Convert a PHP Timestamp to a Date
A PHP timestamp stores the number of seconds since 00:00:00 Jan. 1, 1970, known as the Unix epoch date. This system allows...