{"id":1981,"date":"2022-03-07T11:20:16","date_gmt":"2022-03-07T11:20:16","guid":{"rendered":"https:\/\/swatilathia.com\/?page_id=1981"},"modified":"2025-04-07T07:16:20","modified_gmt":"2025-04-07T07:16:20","slug":"database-connectivity","status":"publish","type":"page","link":"https:\/\/swatilathia.com\/?page_id=1981","title":{"rendered":"Database Connectivity"},"content":{"rendered":"<body>\n<p class=\"has-medium-font-size\">We have already learnt form element in our HTML tutorial. Since we understand that HTML only shows you how your form look like, it can not store\/save your data for future reference. We can not edit or delete that data without storing anywhere. We all know that PHP enhances our website with its better connectivity to database. Here,  we are using PHP with MySQL tool (phpmyadmin). For this, you just need web server (here we are using WAMP server). So let\u2019s start with simple example of student detail.<\/p>\n\n\n\n<p class=\"has-medium-font-size\">We have created our database in phpmyadmin with database name \u201c<strong>db_student<\/strong>\u201c. Table inside this database is \u201c<strong>tbl_stud_detail<\/strong>\u201c. All the fields are : <em>stud_id integer(5) Primary Key Auto Increment<\/em>, <em>stud_name varchar(50)<\/em>, <em>stud_city varchar(50), stud_age integer (3)<\/em><\/p>\n\n\n\n<p class=\"has-medium-font-size\">After creating the table, now we are start creating HTML form from which we can insert data to tbl_stud_detail.<\/p>\n\n\n\n<p>The following file is \u201c<strong>stud_insert.html<\/strong>\u201c<\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;form method=post action=\"stud_insert.php\"&gt;\n\tEnter Student Name :&lt;input type=text name=t1&gt;&lt;br&gt;\n\tEnter Student City :&lt;input type=text name=t2&gt;&lt;br&gt;\n\tEnter Student Age :&lt;input type=number name=t3&gt;&lt;br&gt;\n\t&lt;input type=submit name=s1&gt;&lt;br&gt;\n&lt;\/form&gt;<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\">Now create \u201c<strong>stud_insert.php<\/strong>\u201d file to connect it with database<\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n\/\/Fetch all the values from HTML form elements \n$s_nm=$_POST['t1'];\n$s_city=$_POST['t2'];\n$s_age=$_POST['t3'];\n\n\/\/Connect with server &amp; phpmyadmin database \n$conn=mysqli_connect(\"localhost\",\"root\",\"\");\n$db=mysqli_select_db($conn,\"db_student\");\n\n\/\/Insert query to insert record into table\n$insert_qry=\"INSERT INTO `tbl_stud_detail` \n\t(`stud_name`,`stud_city`,`stud_age`) \n\tVALUES \n\t('$s_nm','$s_city','$s_age')\";\n\n\/\/Execute\/Send the query to phpmyadmin\nmysqli_query($conn,$insert_qry);\n\n\n\/*After sending insert query this page redirects to stud_data.php where a tabular format of data is displayed *\/\nheader(\"location:stud_data.php\");<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\">Now create \u201c<strong>stud_data.php<\/strong>\u201c. This page shows you the inserted records in a tabular format.<\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n\n\/\/Connection &amp; database selection\n$conn=mysqli_connect(\"localhost\",\"root\",\"\");\n$db=mysqli_select_db($conn,\"db_student\");\n\n\/\/Select required columns from table\n$select=\"select * from `tbl_stud_detail`\";\n$result=mysqli_query($conn,$select);\n\necho \"&lt;table border=2&gt;\n\t&lt;tr&gt;\n\t&lt;th&gt;Student Id&lt;\/th&gt;\n\t&lt;th&gt;Student Name&lt;\/th&gt;\n\t&lt;th&gt;City&lt;\/th&gt;\n\t&lt;th&gt;Age&lt;\/th&gt;\n\t&lt;\/tr&gt;\";\n\n\/\/This while loop executes till the record is in the resultset (result returned from SELECT query)\nwhile($r=mysqli_fetch_row($result))\n{\n        echo \"&lt;tr&gt;\n\t\t&lt;td&gt;\".$r[0].\"&lt;\/td&gt;\n\t\t&lt;td&gt;\".$r[1].\"&lt;\/td&gt;\n\t\t&lt;td&gt;\".$r[2].\"&lt;\/td&gt;\n\t\t&lt;td&gt;\".$r[3].\"&lt;\/td&gt;\n\t&lt;\/tr&gt;\";\n}\n\necho \"&lt;\/table&gt;\";\necho \"&lt;br&gt;&lt;a href='stud_insert.html'&gt;Add another record&lt;\/a&gt;\";\n?&gt;<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\">This is how you can insert any data from HTML form to your phpmyadmin database table &amp; fetch them in your webpage as per your requirement in a tabular form.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69df1b68ec185\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69df1b68ec185\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/swatilathia.com\/?page_id=1981\/#Database_connectivity_Videos\" >Database connectivity Videos<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/swatilathia.com\/?page_id=1981\/#Creation_of_Database_and_table_in_MySQL_phpmyadmin\" >Creation of Database and table in MySQL (phpmyadmin)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/swatilathia.com\/?page_id=1981\/#How_to_fetch_the_record_from_Database_table_to_Your_webpagebrowser\" >How to fetch the record from Database table to Your webpage\/browser<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/swatilathia.com\/?page_id=1981\/#How_to_delete_record_from_Database_table\" >How to delete record from Database table<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/swatilathia.com\/?page_id=1981\/#How_to_update_records_in_database_table\" >How to update record(s) in database table<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/swatilathia.com\/?page_id=1981\/#Select_query_Example_fetching_records_from_table\" >Select query Example (fetching records from table)<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Database_connectivity_Videos\"><\/span>Database connectivity Videos<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creation_of_Database_and_table_in_MySQL_phpmyadmin\"><\/span>Creation of Database and table in MySQL (phpmyadmin)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<div class=\"zak-oembed-container\"><div class=\"jetpack-video-wrapper\"><iframe loading=\"lazy\" title=\"PHP MySQL connectivity | Creation of Database &amp; Table in Phpmyadmin | Part 1 in Gujarati\" width=\"812\" height=\"457\" src=\"https:\/\/www.youtube.com\/embed\/KS5TSp7Ttio?list=PLvbhfsw4hYENX7gUHnwaX1tt3I0-nMNRu\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/div><\/div>\n<\/div><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_fetch_the_record_from_Database_table_to_Your_webpagebrowser\"><\/span>How to fetch the record from Database table to Your webpage\/browser<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<div class=\"zak-oembed-container\"><div class=\"jetpack-video-wrapper\"><iframe loading=\"lazy\" title=\"PHP MySQL connectivity | How to fetch the record from table to webpage\/browser | SELECT | Part 2\" width=\"812\" height=\"457\" src=\"https:\/\/www.youtube.com\/embed\/Mw21ZXugB2g?list=PLvbhfsw4hYENX7gUHnwaX1tt3I0-nMNRu\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/div><\/div>\n<\/div><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_delete_record_from_Database_table\"><\/span>How to delete record from Database table<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<div class=\"zak-oembed-container\"><div class=\"jetpack-video-wrapper\"><iframe loading=\"lazy\" title=\"PHP MySQL Connectivity | How to delete record(s) fro database\/table | Part   3 | In Gujarati\" width=\"812\" height=\"457\" src=\"https:\/\/www.youtube.com\/embed\/7T8N6iMkrt8?list=PLvbhfsw4hYENX7gUHnwaX1tt3I0-nMNRu\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/div><\/div>\n<\/div><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_update_records_in_database_table\"><\/span>How to update record(s) in database table<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<div class=\"zak-oembed-container\"><div class=\"jetpack-video-wrapper\"><iframe loading=\"lazy\" title=\"PHP Mysql Connectivity | Update Query | Easy Example in Gujarati\" width=\"812\" height=\"457\" src=\"https:\/\/www.youtube.com\/embed\/Rgi1FZbJoNY?list=PLvbhfsw4hYENX7gUHnwaX1tt3I0-nMNRu\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/div><\/div>\n<\/div><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Select_query_Example_fetching_records_from_table\"><\/span>Select query Example (fetching records from table)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<div class=\"zak-oembed-container\"><div class=\"jetpack-video-wrapper\"><iframe loading=\"lazy\" title=\"PHP MySQL connectivity with Select query example in easy way in Gujarati\" width=\"812\" height=\"457\" src=\"https:\/\/www.youtube.com\/embed\/d6cd7R177nk?list=PLvbhfsw4hYENX7gUHnwaX1tt3I0-nMNRu\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/div><\/div>\n<\/div><\/figure>\n<\/body>","protected":false},"excerpt":{"rendered":"<p>We have already learnt form element in our HTML tutorial. Since we understand that HTML only shows you how your form look like, it can not store\/save your data for future reference. We can not edit or delete that data without storing anywhere. We all know that PHP enhances our website with its better connectivity [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"zakra_page_container_layout":"customizer","zakra_page_sidebar_layout":"customizer","zakra_remove_content_margin":false,"zakra_sidebar":"customizer","zakra_transparent_header":"customizer","zakra_logo":0,"zakra_main_header_style":"default","zakra_menu_item_color":"","zakra_menu_item_hover_color":"","zakra_menu_item_active_color":"","zakra_menu_active_style":"","zakra_page_header":true,"om_disable_all_campaigns":false,"footnotes":""},"class_list":["post-1981","page","type-page","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/pages\/1981","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swatilathia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1981"}],"version-history":[{"count":7,"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/pages\/1981\/revisions"}],"predecessor-version":[{"id":2347,"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/pages\/1981\/revisions\/2347"}],"wp:attachment":[{"href":"https:\/\/swatilathia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1981"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}