Articles related to web development
This tutorial will demonstrate you how to CREATE tables and insert data into it. I assume that you have read tutorial for mySQL connectivity and you have already made config.php Read here
Level : BEGINER
The function we will use is :
mysql_query();
For creating new tables we use the following query.
Syntax : CREATE TABLE tablename(fields)
but we have to use all queries in the function mysql_query()..
so it will be used like this.
I am making a table of members with only id,name and email.
mysql_query(”CREATE TABLE members(id INT(5), name VARCHAR(20), email VARCHAR(20))”);
Ok this will create table with the name members.
It was so easy, isnt it
![]()
Now the process of inserting data into table. We will be using another query for inserting data..
Syntax : INSERT INTO tablename VALUES(fields with values)
This is how you will insert data into table. So it will be used in the fucntion like this.
mysql_query(”INSERT INTO members VALUES(1,’Ali’,'abc@swish-db.com’)”);
Now if you want that ID should be unique everytime, means it cannot be the same. for example 1 is already assign to ALI so 1 cannot be entered again then you can put PRIMARY KEY in front of ID field, while you are creating table, so it will look like this,
mysql_query(”CREATE TABLE members(id INT(5) PRIMARY KEY, name VARCHAR(20), email VARCHAR(20))”);
so this is the basic tutorial for creating table and adding data into it. I hope it was useful.
Leave a reply