Hudzilla.org - the homepage of Paul Hudson
Contents > Databases > SQL Wish List | Report Bug | About Me ]

9.3.6     Inserting data

This is NOT the latest copy of this book; click here for the latest version.

Now that you are able to create, alter, and delete tables at will, we can continue on by looking at how to insert data into our test table. Make sure you have the phpdb database and the original usertable table (that is, with Age and without MiddleName) created before continuing.

To insert data into your table, you use the "INSERT INTO" SQL command:

INSERT INTO usertable VALUES (1, "Jack", "Black", 29);

The INSERT INTO command above tells your database that you would like your data placed into the specified table - usertable, in the example. The data in between the brackets themselves is what goes into your fields, and it should match with the table definition precisely. As usertable had the fields ID INT, FirstName CHAR(255), LastName CHAR(255), and Age INT, the values we're entering are ID 1, FirstName "Jack", LastName "Black", and "Age 29. Note that the character data must be surrounded by quotes (either single or double).

We'll be looking at more advanced data insertion later - for now, it is just important to learn the basics.





<< 9.3.5 Deleting tables   9.3.7 Selecting data >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
Einstein - 29 Aug 2008

Has anyone ever got the security question wrong? 0.o

A PHP User - 29 Aug 2008

I was wondering,
I'm trying to make a game,
But I'm confused on linking the monsters stats to the database,
Also The "Users" stats to the database, with the increase etc.
Maybe if anyone could help me mail me Th3_Designer@ntlworld.com
or visit my website, http://www.iorelias.co.uk,
And contact me by there!
Thanks,
Nice book btw, very helpful!!!

Sker - 29 Aug 2008

How would "Wom's 12" bat" be look?



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is nine plus six?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow