How to Store a Date in a MySQL Database Using PHP Tutorial

MySQL is a free database server often used in small websites with a low startup budget. PHP is also a free language to use on Apache servers. You can use the PHP and MySQL database features to store data. This process allows you to serve and store dynamic data on your web pages.

Instructions

    • 1

      Right-click your PHP file on your computer and select "Open With." Double-click your PHP editor in the list of programs. If you don't have a specific PHP editor, you can double-click the "Notepad" program to edit your code in the Windows text editor.

    • 2

      Type the variables used to retrieve the data from your form. For instance, if you have a form that asks users to submit their name and birthdate, type the following code:

      $name = $_POST['name'];

      $birthdate = $_POST['birthdate'];

      You need one variable for each form value.

    • 3

      Type the code that connects to your MySQL server. This connection object contains your server's name, username and your password. After you connect to the server, you select your database name. Type the following code:

      mysql_connect("server_name", "username", "password");

      mysql_select_db("db_name");

      Replace these values with your own MySQL information.

    • 4

      Insert the data in your MySQL database. You must create an "insert" query to create a new record. For instance, to insert the name and birthdate for a user, use the following query:

      $query = "insert into customers(name, birtdate) values ('" + $name+ "', '" + $birthdate +"')"

      mysql_query($query);

    • 5

      Save your changes by pressing "Ctrl+S." Open the page in your web browser to test the changes and insert data into your tables.

Related Searches:

References

Comments

You May Also Like

Related Ads

Featured