Today lesson is about how to insert data to mysql table using php mechanisms. In last two lessons we learned about how to make a connection and how to create a database and tables. if you have any problems with those things you better read last posts before go through this.
There is no much different between creating table it is just sql string. Lets look at the code.
//make connection $con = mysql_connect("localhost","root","123"); //check connection if(!$con) { die('Could not connect to the database:'.mysql_error()); } //select database $db=mysql_select_db("my_database",$con); if(!$db) { die('Could not connect to the database:'.mysql_error()); } //making sql query string. This table has two columns as name and telephone number $sql="INSERT INTO my_table('Rajika Nanayakkara',071999999)"; //Execute the mysql query and check is execution process is succeeded if(mysql_query($con,$sql)) { echo "Insert Successfully..! "; } else { echo "Error occurred while inserting data :".mysql_error($con); } //close connection mysql_close($con);