O'Reilly logo

PHP and MySQL for Dynamic Web Sites: Visual Quickpro Guide, Second Edition by Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Inserting Records

After your database and its table(s) have been created, you can start populating them using the INSERT command. Before demonstrating the syntax, I want to be explicit as to how you should treat the different data types in your SQL commands. Always abide by these rules:

  • Numeric values shouldn’t be quoted.

  • String values (for CHAR, VARCHAR, and TEXT column types) must always be quoted.

  • Date and time values must always be quoted.

  • Functions cannot be quoted.

  • The word NULL must not be quoted.

With that in mind, there are two formats for inserting data. With the first, you specify the columns to be used:

INSERT INTO tablename (column1,
→ column2 ...) VALUES ('value1',
→ 'value2' ...)

INSERT INTO tablename (column4,
→ column8) VALUES ('valueX', ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required