MySQL Insert Query

Insert Query Syntax

INSERT INTO 'database_name' ( 'column_1_name', 'column_2_name' ) VALUES ( 'value_1', 'value_2' )

To execute MySQL query in PHP is easy, write the following code and replace CODE with your MySQL query:

<?php mysql_query("CODE"); ?>

Insert a row to database

In the previous article I showed you how to create a MySQL database. Now I insert rows into the students table. Remember id has auto increment property, so I do not need to add a value for it, so the first row will have value 1, the second 2, the third 3 and so on.

INSERT INTO 'students' ( 'first_name', 'last_name', 'gender' ) VALUES ( 'Jack', 'Daniels', 'male' )


1 Jack Daniels male 

I inserted a few more rows with the same technique.

End result

1 Jack Daniels male 
2 Lara Croft female
3 Ronald McDonald male
4 Mickey Mouse male

Next to read

Tomorrow I post the next article about MySQL Select Query, learn how to select rows from the database.


Related articles

Email Validation

Email Validation


Learn how to validate email on client side with HTML5, Javascript and on server side with PHP.

Generate Thumbnail on the Fly with PHP

Generate Thumbnail on the Fly with PHP


In a previous artice I already showed you how to generate square thumbnails with PHP. Now I show you how to keep the original ratio of the image and how to control the alignment of the square image.

Facebook Upload Photo to User′s Profile

Facebook Upload Photo to User′s Profile


Learn how to upload a photo to Facebook user′s profile with PHP SDK via Graph API!

Leave a comment

We welcome any comment from you! Please keep in mind that comments are moderated and rel='nofollow' is in use. So, please do not use a domain as your name or a spammy keyword, or your comment will be deleted.

Name: *

E-mail: *

Message: *

Click on the car *

Find us on Facebook



Back to Top