Inserting into MySQL Databases

INSERT INTO

So if we wanted to insert records into our newly created table, the SQL would look something like the following.

"INSERT INTO" tells MySQL that we are going to insert a row into a table. Following that is where the table name goes. After the table name you put the column names for which columns you want to insert information into. Since we have `id` set up as auto increment, we do not have to insert a value for this field. After saying which columns we are inserting data into, we tell MySQL which values will be put in there. "VALUES" is folled by the data in parenthesis. This information needs to be in the same order as you declared the column names. Strings should be enclosed in 'single quotes'. time() is a cool php function that returns an integer of the number of seconds since January 1, 1970. This may seem useless, but we will show some cool things once we get to the retrieving section, which just so happens to be next.

Now that we are connected and we know we want MySQL to do something, we use a function called mysql_query to execute our $sql. This function is passed the SQL to execute and the identifier to the connection.