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);
hi, daniel here, i am just a beginner in programming. I need your advice, cause i want to ask you, if i want to create a stock analyser like buying/selling based on historial data, is learning PHP and mySQL the right path for me?
ReplyDelete(Note: i know there are speardsheets like Excel etc, but i will like to program the those stock strategy by myself and sometimes Excel cannot do the work)
Thanks a lot. haha, i think this is my first comment.
Hi daniel
ReplyDeleteI just saw you comment. it's really depend because PHP is web based scripting language maybe for your stock analyzer program web based system will not suit 100%. so you will need to look at what type of system you are going to make. if it is web base system i would say yes PHP is the best path.
Thanks
ReplyDelete